QMCPACK
OrbitalImages Class Reference

"Estimator" to produce files for orbital plotting. More...

+ Inheritance diagram for OrbitalImages:
+ Collaboration diagram for OrbitalImages:

Public Types

enum  { DIM = OHMMS_DIM }
 
enum  derivative_types_enum { value_d = 0, gradient_d, laplacian_d }
 derivative types More...
 
enum  value_types_enum { real_val = 0, imag_val, abs_val, abs2_val }
 options for orbital value to write More...
 
enum  formats_enum { xsf = 0 }
 options for orbital output file format More...
 
using ValueVector = SPOSet::ValueVector
 
using GradVector = SPOSet::GradVector
 
using Lattice_t = ParticleSet::ParticleLayout
 
using PSPool = std::map< std::string, const std::unique_ptr< ParticleSet > >
 
- Public Types inherited from OperatorBase
enum  EnergyDomains { KINETIC = 0, POTENTIAL, NO_ENERGY_DOMAIN }
 enum to denote energy domain of operators More...
 
enum  QuantumDomains {
  NO_QUANTUM_DOMAIN = 0, CLASSICAL, QUANTUM, CLASSICAL_CLASSICAL,
  QUANTUM_CLASSICAL, QUANTUM_QUANTUM
}
 
enum  {
  PRIMARY = 0, OPTIMIZABLE = 1, RATIOUPDATE = 2, PHYSICAL = 3,
  COLLECTABLE = 4, NONLOCAL = 5
}
 enum for update_mode More...
 
using Return_t = FullPrecRealType
 type of return value of evaluate More...
 
using ValueMatrix = SPOSet::ValueMatrix
 For fast derivative evaluation. More...
 
using GradMatrix = SPOSet::GradMatrix
 
using BufferType = ParticleSet::Buffer_t
 typedef for the serialized buffer More...
 
using Walker_t = ParticleSet::Walker_t
 typedef for the walker More...
 
using ParticleScalar = ParticleSet::Scalar_t
 typedef for the ParticleScalar More...
 
using SPOMap = SPOSet::SPOMap
 typedef for SPOMap More...
 
- Public Types inherited from QMCTraits
enum  { DIM = OHMMS_DIM, DIM_VGL = OHMMS_DIM + 2 }
 
using QTBase = QMCTypes< OHMMS_PRECISION, DIM >
 
using QTFull = QMCTypes< OHMMS_PRECISION_FULL, DIM >
 
using RealType = QTBase::RealType
 
using ComplexType = QTBase::ComplexType
 
using ValueType = QTBase::ValueType
 
using PosType = QTBase::PosType
 
using GradType = QTBase::GradType
 
using TensorType = QTBase::TensorType
 
using IndexType = OHMMS_INDEXTYPE
 define other types More...
 
using FullPrecRealType = QTFull::RealType
 
using FullPrecValueType = QTFull::ValueType
 
using PropertySetType = RecordNamedProperty< FullPrecRealType >
 define PropertyList_t More...
 
using PtclGrpIndexes = std::vector< std::pair< int, int > >
 

Public Member Functions

 OrbitalImages (ParticleSet &P, const PSPool &PSP, Communicate *mpicomm, const SPOMap &spomap)
 
 OrbitalImages (const OrbitalImages &other)
 
std::string getClassName () const override
 return class name More...
 
std::unique_ptr< OperatorBasemakeClone (ParticleSet &P, TrialWaveFunction &psi) final
 
bool put (xmlNodePtr cur) override
 read xml input More...
 
Return_t evaluate (ParticleSet &P) override
 hijack estimator evaluate to evaluate and write all orbitals More...
 
void addObservables (PropertySetType &plist, BufferType &olist) override
 named values to the property list Default implementaton uses addValue(plist_) More...
 
void registerCollectables (std::vector< ObservableHelper > &h5desc, hdf_archive &file) const override
 
void resetTargetParticleSet (ParticleSet &P) override
 Reset the data with the target ParticleSet. More...
 
void setObservables (PropertySetType &plist) override
 Set the values evaluated by this object to plist Default implementation is to assign Value which is updated by evaluate function using my_index_. More...
 
void setParticlePropertyList (PropertySetType &plist, int offset) override
 
void checkout_scalar_arrays (TraceManager &tm)
 
void collect_scalar_samples ()
 
void delete_scalar_arrays ()
 
bool get (std::ostream &os) const override
 write about the class More...
 
void report (const std::string &pad)
 write brief report of configuration data More...
 
void write_orbital (const std::string &sponame, int index, std::vector< ValueType > &orb, value_types_enum value_type, derivative_types_enum derivative_type=value_d, int dimension=0)
 write a single orbital to file More...
 
void write_orbital_xsf (const std::string &sponame, int index, std::vector< ValueType > &orb, value_types_enum value_type, derivative_types_enum derivative_type=value_d, int dimension=0)
 write a single orbital to an xsf file More...
 
- Public Member Functions inherited from OperatorBase
 OperatorBase ()
 Construct a new Operator Base object Default and unique empty constructor. More...
 
virtual ~OperatorBase ()=default
 
virtual bool dependsOnWaveFunction () const
 return true if this operator depends on a wavefunction More...
 
std::bitset< 8 > & getUpdateMode () noexcept
 get update_mode_ reference More...
 
Return_t getValue () const noexcept
 get a copy of value_ More...
 
std::string getName () const noexcept
 getter a copy of my_name_, rvalue small string optimization More...
 
void setName (const std::string name) noexcept
 Set my_name member, uses small string optimization (pass by value) More...
 
TraceRequestgetRequest () noexcept
 Get request_ member. More...
 
virtual void registerObservables (std::vector< ObservableHelper > &h5desc, hdf_archive &file) const
 add to observable descriptor for hdf5 The default implementation is to register a scalar for this->value_ More...
 
virtual void setHistories (Walker_t &ThisWalker)
 
virtual Return_t evaluateDeterministic (ParticleSet &P)
 Evaluate the local energy contribution of this component, deterministically based on current state. More...
 
virtual void mw_evaluate (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const
 Evaluate the contribution of this component of multiple walkers. More...
 
virtual void mw_evaluatePerParticle (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< RealType >> &listeners, const std::vector< ListenerVector< RealType >> &listeners_ions) const
 Evaluate the contribution of this component of multiple walkers per particle and report to registerd listeners from objects in Estimators. More...
 
virtual void mw_evaluateWithParameterDerivatives (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< ParticleSet > &p_list, const opt_variables_type &optvars, const RecordArray< ValueType > &dlogpsi, RecordArray< ValueType > &dhpsioverpsi) const
 TODO: add docs. More...
 
virtual Return_t rejectedMove (ParticleSet &P)
 TODO: add docs. More...
 
virtual Return_t evaluateWithToperator (ParticleSet &P)
 Evaluate the local energy contribution of this component with Toperators updated if requested. More...
 
virtual void mw_evaluateWithToperator (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const
 Evaluate the contribution of this component of multiple walkers. More...
 
virtual void mw_evaluatePerParticleWithToperator (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< RealType >> &listeners, const std::vector< ListenerVector< RealType >> &listeners_ions) const
 Evaluate the contribution of this component of multiple walkers per particle and report to registerd listeners from objects in Estimators. More...
 
virtual Return_t evaluateValueAndDerivatives (ParticleSet &P, const opt_variables_type &optvars, const Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi)
 Evaluate value and derivatives wrt the optimizables. More...
 
virtual Return_t evaluateWithIonDerivs (ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_term, ParticleSet::ParticlePos &pulay_term)
 Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase. More...
 
virtual Return_t evaluateWithIonDerivsDeterministic (ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_term, ParticleSet::ParticlePos &pulay_term)
 Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase. More...
 
virtual void evaluateOneBodyOpMatrix (ParticleSet &P, const TWFFastDerivWrapper &psi, std::vector< ValueMatrix > &B)
 Evaluate "B" matrix for observable. More...
 
virtual void evaluateOneBodyOpMatrixForceDeriv (ParticleSet &P, ParticleSet &source, const TWFFastDerivWrapper &psi, const int iat, std::vector< std::vector< ValueMatrix >> &Bforce)
 Evaluate "dB/dR" matrices for observable. More...
 
virtual void updateSource (ParticleSet &s)
 Update data associated with a particleset. More...
 
virtual Return_t getEnsembleAverage ()
 Return an average value by collective operation. More...
 
virtual void createResource (ResourceCollection &collection) const
 Initialize a shared resource and hand it to a collection. More...
 
virtual void acquireResource (ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const
 Acquire a shared resource from a collection. More...
 
virtual void releaseResource (ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const
 Return a shared resource to a collection. More...
 
virtual void setRandomGenerator (RandomBase< FullPrecRealType > *rng)
 Set the Random Generator object TODO: add docs. More...
 
virtual void add2Hamiltonian (ParticleSet &qp, TrialWaveFunction &psi, QMCHamiltonian &targetH)
 TODO: add docs. More...
 
virtual void getRequiredTraces (TraceManager &tm)
 TODO: add docs. More...
 
virtual void informOfPerParticleListener ()
 
bool isClassical () const noexcept
 
bool isQuantum () const noexcept
 
bool isClassicalClassical () const noexcept
 
bool isQuantumClassical () const noexcept
 
bool isQuantumQuantum () const noexcept
 
bool getMode (const int i) const noexcept
 Return the mode i. More...
 
bool isNonLocal () const noexcept
 TODO: add docs. More...
 
bool hasListener () const noexcept
 
void contributeTraceQuantities ()
 Make trace quantities available. More...
 
void checkoutTraceQuantities (TraceManager &tm)
 Checkout trace arrays Derived classes must guard individual checkouts using request info. More...
 
void collectScalarTraces ()
 Collect scalar trace data. More...
 
void deleteTraceQuantities ()
 delete trace arrays More...
 

Public Attributes

const PSPoolpsetpool
 at put() ion particleset is obtained from ParticleSetPool More...
 
ParticleSetPeln
 electron particleset More...
 
ParticleSetPion
 ion particleset More...
 
Communicatecomm
 mpi communicator More...
 
formats_enum format
 file format selection More...
 
std::vector< value_types_enumvalue_types
 orbital value selections More...
 
bool derivatives
 write out derivatives in addition to values More...
 
std::vector< std::string > sposet_names
 names of sposets to evaluate More...
 
const std::shared_ptr< std::vector< std::vector< int > > > sposet_indices
 indices of orbitals within each sposet to evaluate More...
 
std::vector< std::unique_ptr< SPOSet > > sposets
 sposets obtained by name from SPOMap More...
 
bool center_grid
 evaluate points at grid cell centers instead of edges More...
 
Lattice_t cell
 cell bounding the evaluation grid, default is simulation cell More...
 
PosType corner
 location of cell corner, positions in the cell are corner+uvec*cell More...
 
TinyVector< int, DIMgrid
 number of grid points in each direction (cell axis) More...
 
TinyVector< int, DIMgdims
 stride to generate grid in arbitrary dimensions More...
 
int npoints
 total number of grid points More...
 
int batch_size
 number of orbitals to store in memory at a time (batch_size*npoints) More...
 
ValueVector spo_vtmp
 temporary vector to hold values of all orbitals at a single point More...
 
GradVector spo_gtmp
 temporary vector to hold gradients of all orbitals at a single point More...
 
ValueVector spo_ltmp
 temporary vector to hold laplacians of all orbitals at a single point More...
 
Array< ValueType, 2 > batch_values
 temporary array to hold values of a batch of orbitals at all grid points More...
 
Array< GradType, 2 > batch_gradients
 temporary array to hold gradients of a batch of orbitals at all grid points More...
 
Array< ValueType, 2 > batch_laplacians
 temporary array to hold laplacians of a batch of orbitals at all grid points More...
 
std::vector< ValueTypeorbital
 temporary array to hold values of a single orbital at all grid points More...
 

Private Attributes

const SPOMapspomap_
 reference to the sposet_builder_factory More...
 

Additional Inherited Members

- Protected Member Functions inherited from OperatorBase
virtual void contributeScalarQuantities ()
 
virtual void checkoutScalarQuantities (TraceManager &tm)
 
virtual void collectScalarQuantities ()
 
virtual void deleteScalarQuantities ()
 
virtual void contributeParticleQuantities ()
 
virtual void checkoutParticleQuantities (TraceManager &tm)
 
virtual void deleteParticleQuantities ()
 
virtual void setComputeForces (bool compute)
 
void setEnergyDomain (EnergyDomains edomain)
 Set the Energy Domain. More...
 
void setQuantumDomain (QuantumDomains qdomain)
 set quantum domain More...
 
void oneBodyQuantumDomain (const ParticleSet &P)
 set quantum domain for one-body operator More...
 
void twoBodyQuantumDomain (const ParticleSet &P)
 set quantum domain for two-body operator More...
 
void twoBodyQuantumDomain (const ParticleSet &P1, const ParticleSet &P2)
 set quantum domain for two-body operator More...
 
void addValue (PropertySetType &plist)
 named values to the property list More...
 
- Protected Attributes inherited from OperatorBase
std::bitset< 8 > update_mode_
 set the current update mode More...
 
Return_t value_
 current value More...
 
std::string name_
 name of this object More...
 
TraceRequest request_
 whether traces are being collected More...
 
int my_index_
 starting index of this object More...
 
Return_t new_value_
 a new value for a proposed move More...
 
Walker_tt_walker_
 reference to the current walker More...
 
bool streaming_particles_
 
bool have_required_traces_
 

Detailed Description

"Estimator" to produce files for orbital plotting.

Orbitals are evaluated on a uniform grid and written to ascii files. Only format currently supported is xsf (XCrySDen). Can print real, imag, abs, and abs^2 of each orbital. This class should work with any SPOSet. All work is performed by omp thread 0 of mpi task 0.

TO USE THIS YOU NEED TO KNOW THE NAME OF THE SPOSET(S)!!! For example, using sposet_builder the names are prominently displayed:

<sposet_builder type="bspline" href="pwscf.h5" tilematrix="1 0 0 0 1 0 0 0 1" twistnum="0" source="ion0" version="0.10"> <sposet type="bspline" name="spo_ud" size="2" spindataset="0"> </sposet_builder>

In this case a single sposet named "spo_ud" exists.

If you are using Slater-Jastrow w/o sposet_builder the sposets should be named updet and downdet.

To make xsf files, add xml similar to the following to <hamiltonian>:

minimal working example: single sposet named spo_ud on a 20x20x20 grid

<estimator name="OrbitalImages" type="orbitalimages" ions="ion0"> <parameter name="sposets"> spo_ud </parameter> <parameter name="grid"> 20 20 20 </parameter> </estimator>

as above, but print real, imag, abs, and abs^2 of orbitals (default real)
<estimator name="OrbitalImages" type="orbitalimages" ions="ion0"> <parameter name="sposets"> spo_ud </parameter> <parameter name="grid"> 20 20 20 </parameter> <parameter name="value"> real imag abs abs2 </parameter> </estimator>

up and down sposets named spo_u and spo_d w/ individual orbitals selected
<estimator name="OrbitalImages" type="orbitalimages" ions="ion0"> <parameter name="sposets"> spo_u spo_d </parameter> <parameter name="spo_u"> 13 24 37 </parameter> <parameter name="spo_d"> 10 18 29 41 </parameter> <parameter name="grid"> 20 20 20 </parameter> <parameter name="value"> real imag abs abs2 </parameter> </estimator>

user defined cell by cell center and axes (openbc's, subset of pbc cell)

<estimator name="OrbitalImages" type="orbitalimages" ions="ion0"> <parameter name="sposets"> spo_ud </parameter> <parameter name="grid"> 20 20 20 </parameter> <parameter name="center"> 2.5 2.5 2.5 </parameter> <parameter name="cell"> 5.0 0.0 0.0 0.0 5.0 0.0 0.0 0.0 5.0 </parameter> </estimator>

user defined cell by cell corner and axes (default corner is 0 0 0)

<estimator name="OrbitalImages" type="orbitalimages" ions="ion0"> <parameter name="sposets"> spo_ud </parameter> <parameter name="grid"> 20 20 20 </parameter> <parameter name="corner"> 0.0 0.0 0.0 </parameter> <parameter name="cell"> 5.0 0.0 0.0 0.0 5.0 0.0 0.0 0.0 5.0 </parameter> </estimator>

store only a batch of orbital values in memory this can save on memory for very large grids but will evaluate all orbitals #orbitals/batch_size times

<estimator name="OrbitalImages" type="orbitalimages" ions="ion0"> <parameter name="sposets"> spo_ud </parameter> <parameter name="grid"> 200 200 200 </parameter> <parameter name="batch_size"> 10 </parameter> </estimator>

Definition at line 106 of file OrbitalImages.h.

Member Typedef Documentation

◆ GradVector

Definition at line 115 of file OrbitalImages.h.

◆ Lattice_t

Definition at line 116 of file OrbitalImages.h.

◆ PSPool

using PSPool = std::map<std::string, const std::unique_ptr<ParticleSet> >

Definition at line 117 of file OrbitalImages.h.

◆ ValueVector

Definition at line 114 of file OrbitalImages.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
DIM 

Definition at line 109 of file OrbitalImages.h.

110  {
111  DIM = OHMMS_DIM
112  };
#define OHMMS_DIM
Definition: config.h:64

◆ derivative_types_enum

derivative types

Enumerator
value_d 
gradient_d 
laplacian_d 

Definition at line 120 of file OrbitalImages.h.

◆ formats_enum

options for orbital output file format

Enumerator
xsf 

Definition at line 138 of file OrbitalImages.h.

139  {
140  xsf = 0
141  };

◆ value_types_enum

options for orbital value to write

Enumerator
real_val 
imag_val 
abs_val 
abs2_val 

Definition at line 129 of file OrbitalImages.h.

Constructor & Destructor Documentation

◆ OrbitalImages() [1/2]

OrbitalImages ( ParticleSet P,
const PSPool PSP,
Communicate mpicomm,
const SPOMap spomap 
)

Definition at line 22 of file OrbitalImages.cpp.

References OrbitalImages::comm, and OrbitalImages::Peln.

23  : psetpool(PSP), sposet_indices(std::make_shared<std::vector<std::vector<int>>>()), spomap_(spomap)
24 {
25  //keep the electron particle to get the cell later, if necessary
26  Peln = &P;
27 
28  //keep the communicator to select master task for file write
29  comm = mpicomm;
30 }
const PSPool & psetpool
at put() ion particleset is obtained from ParticleSetPool
const std::shared_ptr< std::vector< std::vector< int > > > sposet_indices
indices of orbitals within each sposet to evaluate
const SPOMap & spomap_
reference to the sposet_builder_factory
Communicate * comm
mpi communicator
ParticleSet * Peln
electron particleset

◆ OrbitalImages() [2/2]

OrbitalImages ( const OrbitalImages other)

Definition at line 32 of file OrbitalImages.cpp.

References OrbitalImages::sposets.

33  : OperatorBase(other),
34  psetpool(other.psetpool),
35  Peln(other.Peln),
36  Pion(other.Pion),
37  comm(other.comm),
38  format(other.format),
39  value_types(other.value_types),
40  derivatives(other.derivatives),
41  sposet_names(other.sposet_names),
42  sposet_indices(other.sposet_indices),
43  center_grid(other.center_grid),
44  cell(other.cell),
45  corner(other.corner),
46  grid(other.grid),
47  gdims(other.gdims),
48  npoints(other.npoints),
49  batch_size(other.batch_size),
50  spo_vtmp(other.spo_vtmp),
51  spo_gtmp(other.spo_gtmp),
52  spo_ltmp(other.spo_ltmp),
53  batch_values(other.batch_values),
54  batch_gradients(other.batch_gradients),
55  batch_laplacians(other.batch_laplacians),
56  orbital(other.orbital),
57  spomap_(other.spomap_)
58 {
59  for (auto& element : other.sposets)
60  sposets.push_back(element->makeClone());
61 }
formats_enum format
file format selection
Array< GradType, 2 > batch_gradients
temporary array to hold gradients of a batch of orbitals at all grid points
bool center_grid
evaluate points at grid cell centers instead of edges
TinyVector< int, DIM > grid
number of grid points in each direction (cell axis)
Array< ValueType, 2 > batch_values
temporary array to hold values of a batch of orbitals at all grid points
const PSPool & psetpool
at put() ion particleset is obtained from ParticleSetPool
std::vector< std::string > sposet_names
names of sposets to evaluate
std::vector< std::unique_ptr< SPOSet > > sposets
sposets obtained by name from SPOMap
OperatorBase()
Construct a new Operator Base object Default and unique empty constructor.
Array< ValueType, 2 > batch_laplacians
temporary array to hold laplacians of a batch of orbitals at all grid points
ParticleSet * Pion
ion particleset
PosType corner
location of cell corner, positions in the cell are corner+uvec*cell
ValueVector spo_ltmp
temporary vector to hold laplacians of all orbitals at a single point
Lattice_t cell
cell bounding the evaluation grid, default is simulation cell
std::vector< ValueType > orbital
temporary array to hold values of a single orbital at all grid points
GradVector spo_gtmp
temporary vector to hold gradients of all orbitals at a single point
const std::shared_ptr< std::vector< std::vector< int > > > sposet_indices
indices of orbitals within each sposet to evaluate
std::vector< value_types_enum > value_types
orbital value selections
int batch_size
number of orbitals to store in memory at a time (batch_size*npoints)
int npoints
total number of grid points
const SPOMap & spomap_
reference to the sposet_builder_factory
Communicate * comm
mpi communicator
ParticleSet * Peln
electron particleset
ValueVector spo_vtmp
temporary vector to hold values of all orbitals at a single point
TinyVector< int, DIM > gdims
stride to generate grid in arbitrary dimensions
bool derivatives
write out derivatives in addition to values

Member Function Documentation

◆ addObservables()

void addObservables ( PropertySetType plist,
BufferType collectables 
)
inlineoverridevirtual

named values to the property list Default implementaton uses addValue(plist_)

Parameters
plistRecordNameProperty
collectablesObservables that are accumulated by evaluate

Reimplemented from OperatorBase.

Definition at line 235 of file OrbitalImages.h.

235 {}

◆ checkout_scalar_arrays()

void checkout_scalar_arrays ( TraceManager tm)
inline

Definition at line 243 of file OrbitalImages.h.

243 {}

◆ collect_scalar_samples()

void collect_scalar_samples ( )
inline

Definition at line 244 of file OrbitalImages.h.

244 {}

◆ delete_scalar_arrays()

void delete_scalar_arrays ( )
inline

Definition at line 245 of file OrbitalImages.h.

245 {}

◆ evaluate()

OrbitalImages::Return_t evaluate ( ParticleSet P)
overridevirtual

hijack estimator evaluate to evaluate and write all orbitals

Implements OperatorBase.

Definition at line 306 of file OrbitalImages.cpp.

References APP_ABORT, qmcplusplus::app_log(), Communicate::barrier(), OrbitalImages::batch_gradients, OrbitalImages::batch_laplacians, OrbitalImages::batch_size, OrbitalImages::batch_values, OrbitalImages::cell, OrbitalImages::center_grid, OrbitalImages::comm, OrbitalImages::corner, OrbitalImages::derivatives, OrbitalImages::DIM, SPOSet::evaluateValue(), SPOSet::evaluateVGL(), OrbitalImages::gdims, OrbitalImages::gradient_d, OrbitalImages::grid, OrbitalImages::laplacian_d, ParticleSet::makeMove(), omptarget::min(), OrbitalImages::npoints, omp_get_thread_num(), OrbitalImages::orbital, ParticleSet::R, Communicate::rank(), ParticleSet::rejectMove(), Array< T, D, ALLOC >::resize(), SPOSet::size(), OrbitalImages::spo_gtmp, OrbitalImages::spo_ltmp, OrbitalImages::spo_vtmp, OrbitalImages::sposet_names, OrbitalImages::sposets, CrystalLattice< T, D >::toCart(), OrbitalImages::value_types, and OrbitalImages::write_orbital().

307 {
308  //only the first thread of the master task writes the orbitals
309  if (comm->rank() == 0 && omp_get_thread_num() == 0)
310  {
311  app_log() << std::endl;
312  app_log() << "OrbitalImages::evaluate writing orbital images" << std::endl;
313 
314  //create the grid points by mapping point index into D-dim points
315  app_log() << " generating grid " << grid << std::endl;
316  std::vector<PosType> rpoints;
317  rpoints.resize(npoints);
318  PosType u, du;
319  for (int d = 0; d < DIM; ++d)
320  du[d] += 1.0 / grid[d];
321  for (int p = 0; p < npoints; ++p)
322  {
323  int nrem = p;
324  for (int d = DIM - 1; d > 0; --d)
325  {
326  int ind = nrem / gdims[d];
327  u[d] = ind * du[d];
328  nrem -= ind * gdims[d];
329  }
330  u[0] = nrem * du[0];
331  if (center_grid)
332  u += 0.5 * du;
333  rpoints[p] = cell.toCart(u) + corner;
334  }
335 
336  //evaluate and write the orbitals for each sposet
337  app_log() << " evaluating all orbitals" << std::endl;
338  for (int i = 0; i < sposets.size(); ++i)
339  {
340  //get sposet information
341  const std::string& sposet_name = sposet_names[i];
342  app_log() << " evaluating orbitals in " + sposet_name + " on the grid" << std::endl;
343  std::vector<int>& sposet_inds = (*sposet_indices)[i];
344  SPOSet& sposet = *sposets[i];
345  int nspo = sposet_inds.size();
346 
347  //set the batch size
348  int bsize = batch_size;
349  if (bsize == -1)
350  bsize = nspo;
351 
352  //resize temporary evaluation arrays
353  spo_vtmp.resize(sposet.size());
354  batch_values.resize(npoints, bsize);
355  orbital.resize(npoints);
356  if (derivatives)
357  {
358  spo_gtmp.resize(sposet.size());
359  spo_ltmp.resize(sposet.size());
362  }
363 
364  //loop over orbitals one batch at a time (batch_size orbitals)
365  int bstart = 0;
366  int bend = std::min(bsize, nspo);
367  while (bstart < nspo)
368  {
369  //fill up the temporary storage for a batch of orbitals
370  app_log() << " evaluating orbital batch " << bstart << " to " << bend << " out of " << nspo << std::endl;
371  for (int p = 0; p < npoints; ++p)
372  {
373  P.makeMove(0, rpoints[p] - P.R[0]);
374  if (!derivatives)
375  {
376  sposet.evaluateValue(P, 0, spo_vtmp); //note that ALL orbitals are evaluated each time
377  for (int b = bstart, ib = 0; b < bend; ++b, ++ib)
378  batch_values(p, ib) = spo_vtmp[sposet_inds[b]];
379  }
380  else
381  {
382  sposet.evaluateVGL(P, 0, spo_vtmp, spo_gtmp, spo_ltmp);
383  for (int b = bstart, ib = 0; b < bend; ++b, ++ib)
384  batch_values(p, ib) = spo_vtmp[sposet_inds[b]];
385  for (int b = bstart, ib = 0; b < bend; ++b, ++ib)
386  batch_gradients(p, ib) = spo_gtmp[sposet_inds[b]];
387  for (int b = bstart, ib = 0; b < bend; ++b, ++ib)
388  batch_laplacians(p, ib) = spo_ltmp[sposet_inds[b]];
389  }
390  P.rejectMove(0);
391  }
392  //write out the batch one orbital at a time for each value type requested
393  app_log() << " writing all orbitals in the batch" << std::endl;
394  for (int b = bstart, ib = 0; b < bend; ++b, ++ib)
395  {
396  //transfer strided orbital info into contiguous array
397  for (int p = 0; p < npoints; ++p)
398  orbital[p] = batch_values(p, ib);
399  //write one file for each value type (real, imag, etc) selected
400  for (int iv = 0; iv < value_types.size(); ++iv)
401  write_orbital(sposet_name, sposet_inds[b], orbital, value_types[iv]);
402  }
403  if (derivatives)
404  {
405  for (int b = bstart, ib = 0; b < bend; ++b, ++ib)
406  {
407  for (int d = 0; d < DIM; ++d)
408  {
409  for (int p = 0; p < npoints; ++p)
410  orbital[p] = batch_gradients(p, ib)[d];
411  for (int iv = 0; iv < value_types.size(); ++iv)
412  write_orbital(sposet_name, sposet_inds[b], orbital, value_types[iv], gradient_d, d);
413  }
414  }
415  for (int b = bstart, ib = 0; b < bend; ++b, ++ib)
416  {
417  for (int p = 0; p < npoints; ++p)
418  orbital[p] = batch_laplacians(p, ib);
419  for (int iv = 0; iv < value_types.size(); ++iv)
420  write_orbital(sposet_name, sposet_inds[b], orbital, value_types[iv], laplacian_d);
421  }
422  }
423  bstart = bend;
424  bend += bsize;
425  bend = std::min(bend, nspo);
426  }
427  }
428 
429  app_log() << "OrbitalImages::evaluate orbital images written successfully, exiting.\n" << std::endl;
430  APP_ABORT(" Not a fatal error, just exiting.");
431  }
432 
433  //make sure no other process runs off
434  comm->barrier();
435 
436  return 0.0;
437 }
void barrier() const
Array< GradType, 2 > batch_gradients
temporary array to hold gradients of a batch of orbitals at all grid points
bool center_grid
evaluate points at grid cell centers instead of edges
int rank() const
return the rank
Definition: Communicate.h:116
TinyVector< int, DIM > grid
number of grid points in each direction (cell axis)
Array< ValueType, 2 > batch_values
temporary array to hold values of a batch of orbitals at all grid points
std::ostream & app_log()
Definition: OutputManager.h:65
std::vector< std::string > sposet_names
names of sposets to evaluate
std::vector< std::unique_ptr< SPOSet > > sposets
sposets obtained by name from SPOMap
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
T min(T a, T b)
Array< ValueType, 2 > batch_laplacians
temporary array to hold laplacians of a batch of orbitals at all grid points
QMCTraits::PosType PosType
void write_orbital(const std::string &sponame, int index, std::vector< ValueType > &orb, value_types_enum value_type, derivative_types_enum derivative_type=value_d, int dimension=0)
write a single orbital to file
omp_int_t omp_get_thread_num()
Definition: OpenMP.h:25
PosType corner
location of cell corner, positions in the cell are corner+uvec*cell
ValueVector spo_ltmp
temporary vector to hold laplacians of all orbitals at a single point
Lattice_t cell
cell bounding the evaluation grid, default is simulation cell
std::vector< ValueType > orbital
temporary array to hold values of a single orbital at all grid points
GradVector spo_gtmp
temporary vector to hold gradients of all orbitals at a single point
std::vector< value_types_enum > value_types
orbital value selections
int batch_size
number of orbitals to store in memory at a time (batch_size*npoints)
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
int npoints
total number of grid points
Communicate * comm
mpi communicator
ValueVector spo_vtmp
temporary vector to hold values of all orbitals at a single point
SingleParticlePos toCart(const TinyVector< T1, D > &c) const
Convert a unit vector to a cartesian vector.
TinyVector< int, DIM > gdims
stride to generate grid in arbitrary dimensions
bool derivatives
write out derivatives in addition to values

◆ get()

bool get ( std::ostream &  os) const
inlineoverridevirtual

write about the class

Implements OperatorBase.

Definition at line 249 of file OrbitalImages.h.

249 { return false; }

◆ getClassName()

std::string getClassName ( ) const
inlineoverridevirtual

return class name

Implements OperatorBase.

Definition at line 220 of file OrbitalImages.h.

220 { return "OrbitalImages"; }

◆ makeClone()

std::unique_ptr< OperatorBase > makeClone ( ParticleSet P,
TrialWaveFunction psi 
)
finalvirtual

Implements OperatorBase.

Definition at line 63 of file OrbitalImages.cpp.

References qmcplusplus::clone.

64 {
65  //cloning shouldn't strictly be necessary, but do it right just in case
66  std::unique_ptr<OrbitalImages> clone = std::make_unique<OrbitalImages>(*this);
67  clone->Peln = &P;
68  return clone;
69 }

◆ put()

bool put ( xmlNodePtr  cur)
overridevirtual

read xml input

Implements OperatorBase.

Definition at line 72 of file OrbitalImages.cpp.

References OrbitalImages::abs2_val, OrbitalImages::abs_val, OhmmsAttributeSet::add(), APP_ABORT, qmcplusplus::app_log(), OrbitalImages::batch_size, OrbitalImages::cell, CrystalLattice< T, D >::Center, OrbitalImages::center_grid, OrbitalImages::corner, OrbitalImages::derivatives, OrbitalImages::DIM, OrbitalImages::format, OrbitalImages::gdims, ParticleSet::get(), ParticleSet::getLattice(), getXMLAttributeValue(), OrbitalImages::grid, OrbitalImages::imag_val, qmcplusplus::n, OperatorBase::name_, OrbitalImages::npoints, OrbitalImages::Peln, OrbitalImages::Pion, OrbitalImages::psetpool, OhmmsAttributeSet::put(), putContent(), OrbitalImages::real_val, OrbitalImages::report(), CrystalLattice< T, D >::set(), OrbitalImages::spomap_, OrbitalImages::sposet_indices, OrbitalImages::sposet_names, OrbitalImages::sposets, OrbitalImages::value_types, and OrbitalImages::xsf.

73 {
74  app_log() << "OrbitalImages::put" << std::endl;
75 
76  //set defaults
77  name_ = "OrbitalImages";
78  derivatives = false;
79  center_grid = false;
80  corner = 0.0;
81  batch_size = -1;
82 
83  //read simple attributes
84  std::string write_report = "yes";
85  std::string ion_psname = "ion0";
86  OhmmsAttributeSet attrib;
87  attrib.add(name_, "name");
88  attrib.add(ion_psname, "ions");
89  attrib.add(write_report, "report");
90  attrib.put(cur);
91 
92  //read parameters
93  bool have_grid = false;
94  bool have_center = false;
95  bool have_corner = false;
96  bool have_cell = false;
97 
98  PosType center;
99  Tensor<RealType, DIM> axes;
100  std::vector<std::string> valtypes;
101  std::vector<std::string> dertypes;
102  std::string file_format = "xsf";
103  std::string der_str = "no";
104  std::string cg_str = "no";
105 
106  xmlNodePtr element = cur->xmlChildrenNode;
107  std::vector<xmlNodePtr> other_elements;
108  while (element != NULL)
109  {
110  std::string ename((const char*)element->name);
111  if (ename == "parameter")
112  {
113  const std::string name(getXMLAttributeValue(element, "name"));
114  if (name == "sposets")
115  putContent(sposet_names, element);
116  else if (name == "batch_size")
117  putContent(batch_size, element);
118  else if (name == "grid")
119  {
120  have_grid = true;
121  putContent(grid, element);
122  }
123  else if (name == "center_grid")
124  putContent(cg_str, element);
125  else if (name == "corner")
126  {
127  have_corner = true;
128  putContent(corner, element);
129  }
130  else if (name == "center")
131  {
132  have_center = true;
133  putContent(center, element);
134  }
135  else if (name == "cell")
136  {
137  have_cell = true;
138  putContent(axes, element);
139  }
140  else if (name == "value")
141  putContent(valtypes, element);
142  else if (name == "derivatives")
143  putContent(der_str, element);
144  else if (name == "format")
145  putContent(file_format, element);
146  else
147  other_elements.push_back(element);
148  }
149  element = element->next;
150  }
151 
152  derivatives = der_str == "yes";
153  center_grid = cg_str == "yes";
154 
155  //second pass parameter read to get orbital indices
156  // each parameter is named after the corresponding sposet
157  sposet_indices->resize(sposet_names.size());
158  for (int n = 0; n < other_elements.size(); ++n)
159  {
160  xmlNodePtr element = other_elements[n];
161  std::string ename((const char*)element->name);
162  if (ename == "parameter")
163  {
164  const std::string name(getXMLAttributeValue(element, "name"));
165  for (int i = 0; i < sposet_names.size(); ++i)
166  if (name == sposet_names[i])
167  putContent((*sposet_indices)[i], element);
168  }
169  }
170 
171  //check that the value types requested are reasonable
172  for (int i = 0; i < valtypes.size(); ++i)
173  {
174  const std::string& valtype = valtypes[i];
175  if (valtype == "real")
176  value_types.push_back(real_val);
177  else if (valtype == "imag")
178  value_types.push_back(imag_val);
179  else if (valtype == "abs")
180  value_types.push_back(abs_val);
181  else if (valtype == "abs2")
182  value_types.push_back(abs2_val);
183  else
184  {
185  APP_ABORT("OrbitalImages::put value type " + valtype + " is unsupported\n valid options are: value, abs, abs2");
186  }
187  }
188  if (value_types.size() == 0)
189  value_types.push_back(real_val);
190 
191  //check the format
192  if (file_format == "xsf")
193  format = xsf;
194  else
195  {
196  APP_ABORT("OrbitalImages::put file format " + file_format + " is invalid\n valid options are: xsf");
197  }
198 
199  //get the ion particleset
200  if (auto pit = psetpool.find(ion_psname); pit == psetpool.end())
201  {
202  APP_ABORT("OrbitalImages::put ParticleSet " + ion_psname + " does not exist");
203  }
204  else
205  Pion = pit->second.get();
206 
207  app_log() << " getting sposets" << std::endl;
208 
209  // get the sposets for image output
210  if (sposet_names.size() == 0)
211  APP_ABORT("OrbitalImages::put must have at least one sposet");
212  for (int i = 0; i < sposet_names.size(); ++i)
213  {
214  auto spo_it = spomap_.find(sposet_names[i]);
215  if (spo_it == spomap_.end())
216  throw std::runtime_error("OrbitalImages::put sposet " + sposet_names[i] + " does not exist.");
217 
218  sposets.push_back(spo_it->second->makeClone());
219  auto& sposet = sposets.back();
220  auto& sposet_inds = (*sposet_indices)[i];
221  if (sposet_inds.size() == 0)
222  for (int n = 0; n < sposet->size(); ++n)
223  sposet_inds.push_back(n);
224  for (int n = 0; n < sposet_inds.size(); ++n)
225  {
226  int index = sposet_inds[n];
227  if (index < 0 || index > sposet->size())
228  {
229  app_log() << "\nindex for sposet " << sposet_names[i] << " is out of range\nindex must be between 0 and "
230  << sposet->size() - 1 << "\nyou provided: " << index << std::endl;
231  APP_ABORT("OrbitalImages::put sposet index out of range, see message above");
232  }
233  }
234  }
235 
236  //check that the grid and cell are properly defined
237  if (!have_grid)
238  APP_ABORT("OrbitalImages::put must provide grid");
239  if (have_corner && have_center)
240  APP_ABORT("OrbitalImages::put corner and center are provided, this is ambiguous");
241  if (have_cell)
242  {
243  cell.set(axes);
244  if (!have_corner && !have_center)
245  APP_ABORT("OrbitalImages::put must provide corner or center");
246  }
247  else
248  cell = Peln->getLattice();
249 
250  //calculate the cell corner in the case that the cell center is provided
251  if (have_center)
252  corner = center - cell.Center;
253 
254  //get the number of grid points
255  npoints = 1;
256  for (int d = 0; d < DIM; ++d)
257  npoints *= grid[d];
258 
259  //get grid strides in D dimensions
260  gdims[0] = 1;
261  for (int d = 1; d < DIM; ++d)
262  gdims[d] = gdims[d - 1] * grid[d - 1];
263 
264  //write a brief report to the log file
265  if (write_report == "yes")
266  report(" ");
267 
268  app_log() << "end OrbitalImages::put" << std::endl;
269  return true;
270 }
void set(const Tensor< TT, D > &lat)
set the lattice vector from the command-line options
SingleParticlePos Center
Center of the cell sum(Rv[i])/2.
formats_enum format
file format selection
bool center_grid
evaluate points at grid cell centers instead of edges
TinyVector< int, DIM > grid
number of grid points in each direction (cell axis)
const PSPool & psetpool
at put() ion particleset is obtained from ParticleSetPool
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::vector< std::string > sposet_names
names of sposets to evaluate
std::vector< std::unique_ptr< SPOSet > > sposets
sposets obtained by name from SPOMap
QMCTraits::PosType PosType
std::string name_
name of this object
Definition: OperatorBase.h:527
ParticleSet * Pion
ion particleset
PosType corner
location of cell corner, positions in the cell are corner+uvec*cell
Lattice_t cell
cell bounding the evaluation grid, default is simulation cell
void report(const std::string &pad)
write brief report of configuration data
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
const std::shared_ptr< std::vector< std::vector< int > > > sposet_indices
indices of orbitals within each sposet to evaluate
std::vector< value_types_enum > value_types
orbital value selections
int batch_size
number of orbitals to store in memory at a time (batch_size*npoints)
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
int npoints
total number of grid points
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
const SPOMap & spomap_
reference to the sposet_builder_factory
const auto & getLattice() const
Definition: ParticleSet.h:251
ParticleSet * Peln
electron particleset
TinyVector< int, DIM > gdims
stride to generate grid in arbitrary dimensions
bool get(std::ostream &os) const override
dummy. For satisfying OhmmsElementBase.
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
bool derivatives
write out derivatives in addition to values

◆ registerCollectables()

void registerCollectables ( std::vector< ObservableHelper > &  h5desc,
hdf_archive file 
) const
inlineoverridevirtual

Reimplemented from OperatorBase.

Definition at line 236 of file OrbitalImages.h.

236 {}

◆ report()

void report ( const std::string &  pad)

write brief report of configuration data

Definition at line 273 of file OrbitalImages.cpp.

References qmcplusplus::app_log(), OrbitalImages::cell, CrystalLattice< T, D >::Center, OrbitalImages::center_grid, OrbitalImages::corner, OrbitalImages::derivatives, OrbitalImages::DIM, OrbitalImages::grid, qmcplusplus::n, OrbitalImages::npoints, CrystalLattice< T, D >::Rv, SPOSet::size(), OrbitalImages::sposet_indices, OrbitalImages::sposet_names, and OrbitalImages::sposets.

Referenced by OrbitalImages::put().

274 {
275  app_log() << pad << "OrbitalImages report" << std::endl;
276  app_log() << pad << " derivatives = " << derivatives << std::endl;
277  app_log() << pad << " nsposets = " << sposets.size() << " " << sposet_names.size() << " "
278  << sposet_indices->size() << std::endl;
279  for (int i = 0; i < sposet_names.size(); ++i)
280  {
281  std::vector<int>& sposet_inds = (*sposet_indices)[i];
282  SPOSet& sposet = *sposets[i];
283  if (sposet_inds.size() == sposet.size())
284  app_log() << pad << " " << sposet_names[i] << " = all " << sposet.size() << " orbitals" << std::endl;
285  else
286  {
287  app_log() << pad << " " << sposet_names[i] << " =";
288  for (int n = 0; n < sposet_inds.size(); ++n)
289  app_log() << " " << sposet_inds[n];
290  app_log() << std::endl;
291  }
292  }
293  app_log() << pad << " npoints = " << npoints << std::endl;
294  app_log() << pad << " grid = " << grid << std::endl;
295  app_log() << pad << " corner = " << corner << std::endl;
296  app_log() << pad << " center = " << corner + cell.Center << std::endl;
297  app_log() << pad << " center_grid = " << center_grid << std::endl;
298  app_log() << pad << " cell " << std::endl;
299  for (int d = 0; d < DIM; ++d)
300  app_log() << pad << " " << d << " " << cell.Rv[d] << std::endl;
301  app_log() << pad << " end cell " << std::endl;
302  app_log() << pad << "end OrbitalImages report" << std::endl;
303 }
SingleParticlePos Center
Center of the cell sum(Rv[i])/2.
bool center_grid
evaluate points at grid cell centers instead of edges
TinyVector< int, DIM > grid
number of grid points in each direction (cell axis)
std::ostream & app_log()
Definition: OutputManager.h:65
std::vector< std::string > sposet_names
names of sposets to evaluate
std::vector< std::unique_ptr< SPOSet > > sposets
sposets obtained by name from SPOMap
TinyVector< SingleParticlePos, D > Rv
Real-space unit vectors.
PosType corner
location of cell corner, positions in the cell are corner+uvec*cell
Lattice_t cell
cell bounding the evaluation grid, default is simulation cell
const std::shared_ptr< std::vector< std::vector< int > > > sposet_indices
indices of orbitals within each sposet to evaluate
int npoints
total number of grid points
bool derivatives
write out derivatives in addition to values

◆ resetTargetParticleSet()

void resetTargetParticleSet ( ParticleSet P)
inlineoverridevirtual

Reset the data with the target ParticleSet.

Parameters
Pnew target ParticleSet

Implements OperatorBase.

Definition at line 239 of file OrbitalImages.h.

239 {}

◆ setObservables()

void setObservables ( PropertySetType plist)
inlineoverridevirtual

Set the values evaluated by this object to plist Default implementation is to assign Value which is updated by evaluate function using my_index_.

Parameters
plistRecordNameProperty

Reimplemented from OperatorBase.

Definition at line 240 of file OrbitalImages.h.

240 {}

◆ setParticlePropertyList()

void setParticlePropertyList ( PropertySetType plist,
int  offset 
)
inlineoverridevirtual

Reimplemented from OperatorBase.

Definition at line 241 of file OrbitalImages.h.

241 {}

◆ write_orbital()

void write_orbital ( const std::string &  sponame,
int  index,
std::vector< ValueType > &  orb,
value_types_enum  value_type,
derivative_types_enum  derivative_type = value_d,
int  dimension = 0 
)

write a single orbital to file

Definition at line 440 of file OrbitalImages.cpp.

References OrbitalImages::format, OrbitalImages::write_orbital_xsf(), and OrbitalImages::xsf.

Referenced by OrbitalImages::evaluate().

446 {
447  //only xsf format is supported for now
448  if (format == xsf)
449  write_orbital_xsf(sponame, index, orb, value_type, derivative_type, dimension);
450 }
formats_enum format
file format selection
void write_orbital_xsf(const std::string &sponame, int index, std::vector< ValueType > &orb, value_types_enum value_type, derivative_types_enum derivative_type=value_d, int dimension=0)
write a single orbital to an xsf file
QMCTraits::FullPrecRealType value_type

◆ write_orbital_xsf()

void write_orbital_xsf ( const std::string &  sponame,
int  index,
std::vector< ValueType > &  orb,
value_types_enum  value_type,
derivative_types_enum  derivative_type = value_d,
int  dimension = 0 
)

write a single orbital to an xsf file

Definition at line 453 of file OrbitalImages.cpp.

References qmcplusplus::Units::distance::A, qmcplusplus::Units::A, qmcplusplus::abs(), OrbitalImages::abs2_val, OrbitalImages::abs_val, APP_ABORT, qmcplusplus::app_log(), B(), qmcplusplus::Units::B, OrbitalImages::cell, qmcplusplus::convert(), qmcplusplus::Units::convert(), OrbitalImages::corner, OrbitalImages::DIM, ParticleSet::getLattice(), ParticleSet::getTotalNum(), OrbitalImages::gradient_d, OrbitalImages::grid, qmcplusplus::imag(), OrbitalImages::imag_val, OrbitalImages::laplacian_d, OrbitalImages::npoints, OrbitalImages::Peln, OrbitalImages::Pion, ParticleSet::R, qmcplusplus::real(), OrbitalImages::real_val, CrystalLattice< T, D >::Rv, ParticleSet::species_from_index(), qmcplusplus::SUPERCELL_BULK, and OrbitalImages::value_d.

Referenced by OrbitalImages::write_orbital().

459 {
460  using Units::A;
461  using Units::B;
462  using Units::convert;
463 
464  //generate file name
465  std::array<char, 100> filename;
466  int file_len{0};
467  if (derivative_type == value_d)
468  {
469  if (value_type == real_val)
470  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d.xsf", sponame.c_str(), index);
471  else if (value_type == imag_val)
472  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_imag.xsf", sponame.c_str(), index);
473  else if (value_type == abs_val)
474  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_abs.xsf", sponame.c_str(), index);
475  else if (value_type == abs2_val)
476  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_abs2.xsf", sponame.c_str(), index);
477  }
478  else if (derivative_type == gradient_d)
479  {
480  if (value_type == real_val)
481  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_grad%1d.xsf", sponame.c_str(), index,
482  dimension);
483  else if (value_type == imag_val)
484  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_grad%1d_imag.xsf", sponame.c_str(),
485  index, dimension);
486  else if (value_type == abs_val)
487  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_grad%1d_abs.xsf", sponame.c_str(),
488  index, dimension);
489  else if (value_type == abs2_val)
490  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_grad%1d_abs2.xsf", sponame.c_str(),
491  index, dimension);
492  }
493  else if (derivative_type == laplacian_d)
494  {
495  if (value_type == real_val)
496  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_lap.xsf", sponame.c_str(), index);
497  else if (value_type == imag_val)
498  file_len =
499  std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_lap_imag.xsf", sponame.c_str(), index);
500  else if (value_type == abs_val)
501  file_len = std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_lap_abs.xsf", sponame.c_str(), index);
502  else if (value_type == abs2_val)
503  file_len =
504  std::snprintf(filename.data(), filename.size(), "%s_orbital_%04d_lap_abs2.xsf", sponame.c_str(), index);
505  }
506  if (file_len < 0)
507  throw std::runtime_error("Error generating filename");
508  std::string output_name(filename.data(), file_len);
509  app_log() << " writing file: " << output_name << std::endl;
510 
511  //get the cell containing the ion positions
512  // assume the evaluation cell if any boundaries are open
513  ParticleSet& Pc = *Pion;
514  const Lattice_t& Lbox = Peln->getLattice().SuperCellEnum == SUPERCELL_BULK ? Peln->getLattice() : cell;
515 
516  //open the file
517  std::ofstream file;
518  file.open(output_name, std::ios::out | std::ios::trunc);
519  if (!file.is_open())
520  APP_ABORT("OrbitalImages::write_orbital\n failed to open file for output: " + output_name);
521 
522  //set the precision & number of columns
523  file.precision(6);
524  file << std::scientific;
525  int columns = 5;
526 
527  //get the number of atoms
528  int natoms = Pc.getTotalNum();
529 
530  //write the cell, atomic positions, and orbital to the file in xsf format
531  file << " CRYSTAL" << std::endl;
532  file << " PRIMVEC" << std::endl;
533  for (int i = 0; i < DIM; ++i)
534  {
535  file << " ";
536  for (int d = 0; d < DIM; ++d)
537  file << " " << convert(Lbox.Rv[i][d], B, A);
538  file << std::endl;
539  }
540  file << " PRIMCOORD" << std::endl;
541  file << " " << natoms << " 1" << std::endl;
542  for (int i = 0; i < natoms; ++i)
543  {
544  file << " " << Pc.species_from_index(i);
545  for (int d = 0; d < DIM; ++d)
546  file << " " << convert(Pc.R[i][d], B, A);
547  file << std::endl;
548  }
549  file << " BEGIN_BLOCK_DATAGRID_3D" << std::endl;
550  file << " orbital " << index << std::endl;
551  file << " DATAGRID_3D_ORBITAL" << std::endl;
552  file << " ";
553  for (int d = 0; d < DIM; ++d)
554  file << " " << grid[d];
555  file << std::endl;
556  file << " ";
557  for (int d = 0; d < DIM; ++d)
558  file << " " << convert(corner[d], B, A);
559  file << std::endl;
560  for (int i = 0; i < DIM; ++i)
561  {
562  file << " ";
563  for (int d = 0; d < DIM; ++d)
564  file << " " << convert(cell.Rv[i][d], B, A);
565  file << std::endl;
566  }
567  file << " ";
568  if (value_type == real_val) // real part
569  for (int p = 0; p < npoints; ++p)
570  {
571  file << " " << real(orb[p]);
572  if ((p + 1) % columns == 0)
573  file << std::endl << " ";
574  }
575  else if (value_type == imag_val) // imag part
576  for (int p = 0; p < npoints; ++p)
577  {
578  file << " " << imag(orb[p]);
579  if ((p + 1) % columns == 0)
580  file << std::endl << " ";
581  }
582  else if (value_type == abs_val) // modulus
583  for (int p = 0; p < npoints; ++p)
584  {
585  file << " " << std::abs(orb[p]);
586  if ((p + 1) % columns == 0)
587  file << std::endl << " ";
588  }
589  else if (value_type == abs2_val) // modulus^2
590  for (int p = 0; p < npoints; ++p)
591  {
592  file << " " << std::abs(orb[p]) * std::abs(orb[p]);
593  if ((p + 1) % columns == 0)
594  file << std::endl << " ";
595  }
596  file << std::endl;
597  file << " END_DATAGRID_3D" << std::endl;
598  file << " END_BLOCK_DATAGRID_3D" << std::endl;
599 }
TinyVector< int, DIM > grid
number of grid points in each direction (cell axis)
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
void convert(const PL &lat, const PV &pin, PV &pout)
std::ostream & app_log()
Definition: OutputManager.h:65
float real(const float &c)
real part of a scalar. Cannot be replaced by std::real due to AFQMC specific needs.
TinyVector< SingleParticlePos, D > Rv
Real-space unit vectors.
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...
ParticleSet * Pion
ion particleset
PosType corner
location of cell corner, positions in the cell are corner+uvec*cell
real convert(real value, units units_in, units units_out)
Lattice_t cell
cell bounding the evaluation grid, default is simulation cell
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
ParticleSet::ParticleLayout Lattice_t
int npoints
total number of grid points
const auto & getLattice() const
Definition: ParticleSet.h:251
ParticleSet * Peln
electron particleset
double B(double x, int k, int i, const std::vector< double > &t)
QMCTraits::FullPrecRealType value_type

Member Data Documentation

◆ batch_gradients

Array<GradType, 2> batch_gradients

temporary array to hold gradients of a batch of orbitals at all grid points

Definition at line 208 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate().

◆ batch_laplacians

Array<ValueType, 2> batch_laplacians

temporary array to hold laplacians of a batch of orbitals at all grid points

Definition at line 211 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate().

◆ batch_size

int batch_size

number of orbitals to store in memory at a time (batch_size*npoints)

Definition at line 193 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), and OrbitalImages::put().

◆ batch_values

Array<ValueType, 2> batch_values

temporary array to hold values of a batch of orbitals at all grid points

Definition at line 205 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate().

◆ cell

Lattice_t cell

cell bounding the evaluation grid, default is simulation cell

Definition at line 178 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), OrbitalImages::put(), OrbitalImages::report(), and OrbitalImages::write_orbital_xsf().

◆ center_grid

bool center_grid

evaluate points at grid cell centers instead of edges

Definition at line 175 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), OrbitalImages::put(), and OrbitalImages::report().

◆ comm

Communicate* comm

mpi communicator

Definition at line 153 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), and OrbitalImages::OrbitalImages().

◆ corner

PosType corner

location of cell corner, positions in the cell are corner+uvec*cell

Definition at line 181 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), OrbitalImages::put(), OrbitalImages::report(), and OrbitalImages::write_orbital_xsf().

◆ derivatives

bool derivatives

write out derivatives in addition to values

Definition at line 163 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), OrbitalImages::put(), and OrbitalImages::report().

◆ format

formats_enum format

file format selection

Definition at line 157 of file OrbitalImages.h.

Referenced by OrbitalImages::put(), and OrbitalImages::write_orbital().

◆ gdims

TinyVector<int, DIM> gdims

stride to generate grid in arbitrary dimensions

Definition at line 187 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), and OrbitalImages::put().

◆ grid

TinyVector<int, DIM> grid

number of grid points in each direction (cell axis)

Definition at line 184 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), OrbitalImages::put(), OrbitalImages::report(), and OrbitalImages::write_orbital_xsf().

◆ npoints

int npoints

total number of grid points

Definition at line 190 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), OrbitalImages::put(), OrbitalImages::report(), and OrbitalImages::write_orbital_xsf().

◆ orbital

std::vector<ValueType> orbital

temporary array to hold values of a single orbital at all grid points

Definition at line 214 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate().

◆ Peln

ParticleSet* Peln

electron particleset

Definition at line 147 of file OrbitalImages.h.

Referenced by OrbitalImages::OrbitalImages(), OrbitalImages::put(), and OrbitalImages::write_orbital_xsf().

◆ Pion

ParticleSet* Pion

ion particleset

Definition at line 150 of file OrbitalImages.h.

Referenced by OrbitalImages::put(), and OrbitalImages::write_orbital_xsf().

◆ psetpool

const PSPool& psetpool

at put() ion particleset is obtained from ParticleSetPool

Definition at line 144 of file OrbitalImages.h.

Referenced by OrbitalImages::put().

◆ spo_gtmp

GradVector spo_gtmp

temporary vector to hold gradients of all orbitals at a single point

Definition at line 199 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate().

◆ spo_ltmp

ValueVector spo_ltmp

temporary vector to hold laplacians of all orbitals at a single point

Definition at line 202 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate().

◆ spo_vtmp

ValueVector spo_vtmp

temporary vector to hold values of all orbitals at a single point

Definition at line 196 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate().

◆ spomap_

const SPOMap& spomap_
private

reference to the sposet_builder_factory

Definition at line 273 of file OrbitalImages.h.

Referenced by OrbitalImages::put().

◆ sposet_indices

const std::shared_ptr<std::vector<std::vector<int> > > sposet_indices

indices of orbitals within each sposet to evaluate

Definition at line 169 of file OrbitalImages.h.

Referenced by OrbitalImages::put(), and OrbitalImages::report().

◆ sposet_names

std::vector<std::string> sposet_names

names of sposets to evaluate

Definition at line 166 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), OrbitalImages::put(), and OrbitalImages::report().

◆ sposets

std::vector<std::unique_ptr<SPOSet> > sposets

sposets obtained by name from SPOMap

Definition at line 172 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), OrbitalImages::OrbitalImages(), OrbitalImages::put(), and OrbitalImages::report().

◆ value_types

std::vector<value_types_enum> value_types

orbital value selections

Definition at line 160 of file OrbitalImages.h.

Referenced by OrbitalImages::evaluate(), and OrbitalImages::put().


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