QMCPACK
XMLSaveParticle Class Reference
+ Inheritance diagram for XMLSaveParticle:
+ Collaboration diagram for XMLSaveParticle:

Public Member Functions

 XMLSaveParticle (Particle_t &pin)
 
 ~XMLSaveParticle () override
 
void reset (const char *fileroot, bool append=false) override
 
void report (int iter) override
 
void finalize () override
 
bool put (xmlNodePtr cur) override
 
void get (std::ostream &os, int olevel) const
 
xmlNodePtr createNode (bool addlattice)
 create particleset node More...
 
- Public Member Functions inherited from RecordProperty
 RecordProperty ()
 
virtual ~RecordProperty ()
 

Private Types

using Particle_t = ParticleSet
 
using ParticleIndex = Particle_t::ParticleIndex
 
using ParticleScalar = Particle_t::ParticleScalar
 
using ParticlePos = Particle_t::ParticlePos
 
using ParticleTensor = Particle_t::ParticleTensor
 

Private Attributes

Particle_tref_
 
AttribListType ref_AttribList
 
std::string FileRoot
 
std::vector< std::string > SpeciesName
 

Additional Inherited Members

- Public Types inherited from ParticleTags
enum  {
  PA_IndexType = 0, PA_ScalarType, PA_StringType, PA_PositionType,
  PA_TensorType, PA_UnkownType
}
 enumeraton for datatypes for particle attributes More...
 
- Public Attributes inherited from RecordProperty
int stride
 
std::string FileName
 
- Static Public Attributes inherited from ParticleTags
static std::string null_tag = "null"
 type names of particle attributes, e.g., posArray More...
 
static std::string indextype_tag = "indexArray"
 the datatype tag for the index-type attribute More...
 
static std::string scalartype_tag = "scalarArray"
 the datatype tag for the scalar-type attribute More...
 
static std::string stringtype_tag = "stringArray"
 the datatype tag for the string-type attribute More...
 
static std::string postype_tag = "posArray"
 the datatype tag for the pos-type attribute More...
 
static std::string gradtype_tag = "gradArray"
 the datatype tag for the gradient-type attribute More...
 
static std::string laptype_tag = "lapArray"
 the datatype tag for the laplacian-type attribute More...
 
static std::string tensortype_tag = "tensorArray"
 the datatype tag for the tensor-type attribute More...
 
static std::string xmoltype_tag = "xmolArray"
 the datatype tag for the xmol-type attribute More...
 
static std::string position_tag = "position"
 names of particle attributes, e.g., position More...
 
static std::string spins_tag = "spins"
 the name for spins attribute More...
 
static std::string id_tag = "id"
 the name for id attribute More...
 
static std::string ionid_tag = "ionid"
 the name for ionid attribute More...
 
static std::string trajectory_tag = "trajectory"
 the name for trajectory attribute More...
 
static std::string force_tag = "f"
 the name for force attribute More...
 
static std::string velocity_tag = "v"
 the name for velocity attribute More...
 
static std::string energy_tag = "e"
 the name for energy attribute More...
 
static std::string sumbc_tag = "sumbc"
 the name for sumbc (accumulative boundary crossings) attribute More...
 
static std::string root_tag = "particleset"
 xml element names More...
 
static std::string attrib_tag = "attrib"
 the name of particle attribute node More...
 
static std::string name_tag = "name"
 the attribute name of name More...
 
static std::string datatype_tag = "datatype"
 the attribute name of datatype More...
 
static std::string condition_tag = "condition"
 the attribute name of condition More...
 
static std::string size_tag = "size"
 the attribute name of size More...
 
static std::string format_tag = "format"
 the attribute name of format More...
 
static std::string role_tag = "role"
 the attribute name of role More...
 

Detailed Description

Definition at line 128 of file XMLParticleIO.h.

Member Typedef Documentation

◆ Particle_t

using Particle_t = ParticleSet
private

Definition at line 130 of file XMLParticleIO.h.

◆ ParticleIndex

Definition at line 131 of file XMLParticleIO.h.

◆ ParticlePos

Definition at line 133 of file XMLParticleIO.h.

◆ ParticleScalar

Definition at line 132 of file XMLParticleIO.h.

◆ ParticleTensor

Definition at line 134 of file XMLParticleIO.h.

Constructor & Destructor Documentation

◆ XMLSaveParticle()

Definition at line 486 of file XMLParticleIO.cpp.

486 : ref_(pin) {}

◆ ~XMLSaveParticle()

~XMLSaveParticle ( )
override

Definition at line 488 of file XMLParticleIO.cpp.

488 {}

Member Function Documentation

◆ createNode()

xmlNodePtr createNode ( bool  addlattice)

create particleset node

Parameters
addlatticeif true, add unitcell

Definition at line 611 of file XMLParticleIO.cpp.

References ParticleSet::first(), OhmmsElementBase::getName(), ParticleSet::getSpeciesSet(), SpeciesSet::getTotalNum(), ParticleSet::getTotalNum(), ParticleSet::GroupID, ParticleSet::groups(), ParticleSet::last(), ParticleSet::R, XMLSaveParticle::ref_, SpeciesSet::speciesName, and XMLSaveParticle::SpeciesName.

Referenced by QMCGaussianParserBase::createIonSet().

612 {
613  if (SpeciesName.size() != ref_.getSpeciesSet().getTotalNum())
614  {
616  }
617  //if(addlattice) {
618  // ref_.getLattice().print(std::cout);
619  //}
620  xmlNodePtr cur = xmlNewNode(NULL, (const xmlChar*)"particleset");
621  xmlNewProp(cur, (const xmlChar*)"name", (const xmlChar*)ref_.getName().c_str());
622  if (ref_.groups() > 1)
623  {
624  const SpeciesSet& mySpecies(ref_.getSpeciesSet());
625  int nitem(mySpecies.numAttributes());
626  int nspecies(mySpecies.getTotalNum());
627  for (int is = 0; is < nspecies; is++)
628  {
629  std::ostringstream ng;
630  ng << ref_.last(is) - ref_.first(is);
631  xmlNodePtr g = xmlNewNode(NULL, (const xmlChar*)"group");
632  xmlNewProp(g, (const xmlChar*)"name", (const xmlChar*)SpeciesName[is].c_str());
633  xmlNewProp(g, (const xmlChar*)"size", (const xmlChar*)ng.str().c_str());
634  for (int item = 0; item < nitem; item++)
635  {
636  std::ostringstream prop;
637  prop << mySpecies(item, is);
638  xmlNodePtr p = xmlNewTextChild(g, NULL, (const xmlChar*)"parameter", (const xmlChar*)prop.str().c_str());
639  xmlNewProp(p, (const xmlChar*)"name", (const xmlChar*)mySpecies.attribName[item].c_str());
640  }
641  std::ostringstream pos;
642  pos.setf(std::ios_base::scientific);
643  pos << "\n";
644  for (int iat = ref_.first(is); iat < ref_.last(is); iat++)
645  {
646  pos << ref_.R[iat] << std::endl;
647  }
648  xmlNodePtr posPtr = xmlNewTextChild(g, NULL, (const xmlChar*)"attrib", (const xmlChar*)pos.str().c_str());
649  xmlNewProp(posPtr, (const xmlChar*)"name", (const xmlChar*)"position");
650  xmlNewProp(posPtr, (const xmlChar*)"datatype", (const xmlChar*)"posArray");
651  xmlAddChild(cur, g);
652  }
653  }
654  else
655  {
656  std::ostringstream nat;
657  nat << ref_.getTotalNum();
658  xmlNewProp(cur, (const xmlChar*)"size", (const xmlChar*)nat.str().c_str());
659  const SpeciesSet& mySpecies(ref_.getSpeciesSet());
660  int nitem(mySpecies.numAttributes());
661  int nspecies(mySpecies.getTotalNum());
662  for (int is = 0; is < nspecies; is++)
663  {
664  xmlNodePtr g = xmlNewNode(NULL, (const xmlChar*)"group");
665  xmlNewProp(g, (const xmlChar*)"name", (const xmlChar*)SpeciesName[is].c_str());
666  for (int item = 0; item < nitem; item++)
667  {
668  std::ostringstream prop;
669  prop << mySpecies(item, is);
670  xmlNodePtr p = xmlNewTextChild(g, NULL, (const xmlChar*)"parameter", (const xmlChar*)prop.str().c_str());
671  xmlNewProp(p, (const xmlChar*)"name", (const xmlChar*)mySpecies.attribName[item].c_str());
672  }
673  xmlAddChild(cur, g);
674  }
675  std::ostringstream pos, gid;
676  pos.setf(std::ios_base::scientific);
677  pos << "\n";
678  for (int iat = 0; iat < ref_.getTotalNum(); iat++)
679  {
680  pos << ref_.R[iat] << std::endl;
681  }
682  xmlNodePtr posPtr = xmlNewTextChild(cur, NULL, (const xmlChar*)"attrib", (const xmlChar*)pos.str().c_str());
683  xmlNewProp(posPtr, (const xmlChar*)"name", (const xmlChar*)"position");
684  xmlNewProp(posPtr, (const xmlChar*)"datatype", (const xmlChar*)"posArray");
685  gid << "\n ";
686  for (int iat = 0; iat < ref_.getTotalNum(); iat++)
687  {
688  gid << SpeciesName[ref_.GroupID[iat]] << " ";
689  }
690  gid << std::endl;
691  xmlNodePtr gPtr = xmlNewTextChild(cur, NULL, (const xmlChar*)"attrib", (const xmlChar*)gid.str().c_str());
692  xmlNewProp(gPtr, (const xmlChar*)"name", (const xmlChar*)"ionid");
693  xmlNewProp(gPtr, (const xmlChar*)"datatype", (const xmlChar*)"stringArray");
694  }
695  return cur;
696 }
const std::string & getName() const
return the name
size_t getTotalNum() const
Definition: ParticleSet.h:493
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
std::vector< std::string > SpeciesName
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
int getTotalNum() const
return the number of species
Definition: SpeciesSet.h:55
int groups() const
return the number of groups
Definition: ParticleSet.h:511
ParticlePos R
Position.
Definition: ParticleSet.h:79
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44

◆ finalize()

void finalize ( )
inlineoverridevirtual

Implements RecordProperty.

Definition at line 150 of file XMLParticleIO.h.

150 {}

◆ get()

void get ( std::ostream &  os,
int  olevel 
) const

Definition at line 508 of file XMLParticleIO.cpp.

References OhmmsElementBase::begin_node(), OhmmsElementBase::end_node(), LatticeXMLWriter::get(), ParticleSet::getLattice(), ParticleSet::getTotalNum(), ParticleSet::GroupID, ParticleSet::R, XMLSaveParticle::ref_, and XMLSaveParticle::SpeciesName.

509 {
510  ref_.begin_node(fxml);
511  fxml.setf(std::ios::scientific);
512  fxml.precision(15);
513  LatticeXMLWriter latticeout(ref_.getLattice());
514  latticeout.get(fxml);
515  for (int i = 0; i < SpeciesName.size(); i++)
516  {
517  fxml << "<group name=\"" << SpeciesName[i] << "\"/>" << std::endl;
518  }
519  //only write the local particles
520  int nloc = ref_.getTotalNum();
521  if (olevel)
522  {
523  /*
524  Particle_t::PAListIterator it = ref_.first_attrib();
525  while(it != ref_.last_attrib())
526  {
527  OhmmsObject* ooref= (*it).second;
528 // if(ooref->objName() == ionid_tag) {
529 // IonName.begin_node(fxml);
530 // for(int iat=0; iat<nloc; iat++) {
531 // fxml << IonName[iat] << " ";
532 // if(iat%20 == 19) fxml << std::endl;
533 // }
534 // IonName.end_node(fxml);
535 // } else {
536  int t_id = ref_AttribList.getAttribType(otype);
537  int o_id = ooref->id();
538  ooref->begin_node(fxml);
539  if(t_id == PA_IndexType)
540  {
541  const ParticleIndex* itmp=dynamic_cast<ParticleIndex*>(ooref);
542  for(int iat=0; iat<nloc; iat++)
543  {
544  fxml << (*itmp)[iat] << " ";
545  if(iat%20 == 19)
546  fxml << std::endl;
547  }
548  }
549  else if(t_id == PA_ScalarType)
550  {
551  fxml.precision(6);
552  const ParticleScalar* stmp=dynamic_cast<ParticleScalar*>(ooref);
553  for(int iat=0; iat<nloc; iat++)
554  {
555  fxml << (*stmp)[iat] << " ";
556  if(iat%5 == 4)
557  fxml << std::endl;
558  }
559  if(nloc%5 != 0)
560  fxml<< std::endl;
561  }
562  else if (t_id == PA_PositionType)
563  {
564  fxml.precision(15);
565  const ParticlePos* rtmp=dynamic_cast<ParticlePos*>(ooref);
566  for(int iat=0; iat<nloc; iat++)
567  {
568  fxml << (*rtmp)[iat] << std::endl;
569  }
570  }
571  else if (t_id == PA_TensorType)
572  {
573  fxml.precision(15);
574  const ParticleTensor* ttmp=dynamic_cast<ParticleTensor*>(ooref);
575  for(int iat=0; iat<nloc; iat++)
576  {
577  fxml << (*ttmp)[iat];
578  }
579  }
580  ooref->end_node(fxml);
581  // }
582  it++;
583  }
584  */
585  }
586  else
587  {
588  ref_.R.begin_node(fxml);
589  for (int iat = 0; iat < nloc; iat++)
590  fxml << ref_.R[iat] << std::endl;
591  ref_.R.end_node(fxml);
592  ref_.GroupID.begin_node(fxml);
593  for (int iat = 0; iat < nloc; iat++)
594  {
595  fxml << ref_.GroupID[iat] << " ";
596  if (iat % 20 == 19)
597  fxml << std::endl;
598  }
599  if (nloc % 20 != 19)
600  fxml << std::endl;
601  ref_.GroupID.end_node(fxml);
602  }
603  ref_.end_node(fxml);
604 }
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::vector< std::string > SpeciesName
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
virtual void begin_node(std::ostream &os) const
write the start of a node
ParticlePos R
Position.
Definition: ParticleSet.h:79
const auto & getLattice() const
Definition: ParticleSet.h:251
virtual void end_node(std::ostream &os) const
write the end of a node

◆ put()

bool put ( xmlNodePtr  cur)
overridevirtual

Implements RecordProperty.

Definition at line 606 of file XMLParticleIO.cpp.

606 { return true; }

◆ report()

void report ( int  iter)
overridevirtual

Implements RecordProperty.

Definition at line 499 of file XMLParticleIO.cpp.

References RecordProperty::FileName.

500 {
501  // writing a meta file
502  std::ofstream fxml(FileName.c_str()); // always overwrite
503  fxml << "<?xml version=\"1.0\"?>" << std::endl;
504  get(fxml, 1);
505  fxml.close();
506 }
std::string FileName

◆ reset()

void reset ( const char *  fileroot,
bool  append = false 
)
overridevirtual

Implements RecordProperty.

Definition at line 490 of file XMLParticleIO.cpp.

References RecordProperty::FileName, XMLSaveParticle::FileRoot, ParticleSet::getSpeciesSet(), XMLSaveParticle::ref_, SpeciesSet::speciesName, and XMLSaveParticle::SpeciesName.

491 {
492  //append is ignored
493  FileRoot = fileroot;
494  FileName = fileroot;
495  FileName.append(".xml");
497 }
std::string FileName
std::vector< std::string > SpeciesName
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44

Member Data Documentation

◆ FileRoot

std::string FileRoot
private

Definition at line 138 of file XMLParticleIO.h.

Referenced by XMLSaveParticle::reset().

◆ ref_

Particle_t& ref_
private

◆ ref_AttribList

AttribListType ref_AttribList
private

Definition at line 137 of file XMLParticleIO.h.

◆ SpeciesName

std::vector<std::string> SpeciesName
private

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