23 : psetpool(PSP), sposet_indices(
std::make_shared<
std::vector<
std::vector<int>>>()), spomap_(
spomap)
34 psetpool(other.psetpool),
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),
48 npoints(other.npoints),
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_)
59 for (
auto& element : other.
sposets)
60 sposets.push_back(element->makeClone());
66 std::unique_ptr<OrbitalImages>
clone = std::make_unique<OrbitalImages>(*this);
74 app_log() <<
"OrbitalImages::put" << std::endl;
77 name_ =
"OrbitalImages";
84 std::string write_report =
"yes";
85 std::string ion_psname =
"ion0";
88 attrib.
add(ion_psname,
"ions");
89 attrib.
add(write_report,
"report");
93 bool have_grid =
false;
94 bool have_center =
false;
95 bool have_corner =
false;
96 bool have_cell =
false;
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";
106 xmlNodePtr element = cur->xmlChildrenNode;
107 std::vector<xmlNodePtr> other_elements;
108 while (element != NULL)
110 std::string ename((
const char*)element->name);
111 if (ename ==
"parameter")
114 if (name ==
"sposets")
116 else if (name ==
"batch_size")
118 else if (name ==
"grid")
123 else if (name ==
"center_grid")
125 else if (name ==
"corner")
130 else if (name ==
"center")
135 else if (name ==
"cell")
140 else if (name ==
"value")
142 else if (name ==
"derivatives")
144 else if (name ==
"format")
147 other_elements.push_back(element);
149 element = element->next;
158 for (
int n = 0;
n < other_elements.size(); ++
n)
160 xmlNodePtr element = other_elements[
n];
161 std::string ename((
const char*)element->name);
162 if (ename ==
"parameter")
172 for (
int i = 0; i < valtypes.size(); ++i)
174 const std::string& valtype = valtypes[i];
175 if (valtype ==
"real")
177 else if (valtype ==
"imag")
179 else if (valtype ==
"abs")
181 else if (valtype ==
"abs2")
185 APP_ABORT(
"OrbitalImages::put value type " + valtype +
" is unsupported\n valid options are: value, abs, abs2");
192 if (file_format ==
"xsf")
196 APP_ABORT(
"OrbitalImages::put file format " + file_format +
" is invalid\n valid options are: xsf");
202 APP_ABORT(
"OrbitalImages::put ParticleSet " + ion_psname +
" does not exist");
207 app_log() <<
" getting sposets" << std::endl;
211 APP_ABORT(
"OrbitalImages::put must have at least one sposet");
216 throw std::runtime_error(
"OrbitalImages::put sposet " +
sposet_names[i] +
" does not exist.");
218 sposets.push_back(spo_it->second->makeClone());
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)
226 int index = sposet_inds[
n];
227 if (index < 0 || index > sposet->size())
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");
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");
244 if (!have_corner && !have_center)
245 APP_ABORT(
"OrbitalImages::put must provide corner or center");
256 for (
int d = 0; d <
DIM; ++d)
261 for (
int d = 1; d <
DIM; ++d)
265 if (write_report ==
"yes")
268 app_log() <<
"end OrbitalImages::put" << std::endl;
275 app_log() << pad <<
"OrbitalImages report" << std::endl;
281 std::vector<int>& sposet_inds = (*sposet_indices)[i];
283 if (sposet_inds.size() == sposet.
size())
288 for (
int n = 0;
n < sposet_inds.size(); ++
n)
294 app_log() << pad <<
" grid = " <<
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;
312 app_log() <<
"OrbitalImages::evaluate writing orbital images" << std::endl;
315 app_log() <<
" generating grid " <<
grid << std::endl;
316 std::vector<PosType> rpoints;
319 for (
int d = 0; d <
DIM; ++d)
320 du[d] += 1.0 /
grid[d];
321 for (
int p = 0; p <
npoints; ++p)
324 for (
int d =
DIM - 1; d > 0; --d)
326 int ind = nrem /
gdims[d];
328 nrem -= ind *
gdims[d];
337 app_log() <<
" evaluating all orbitals" << std::endl;
338 for (
int i = 0; i <
sposets.size(); ++i)
342 app_log() <<
" evaluating orbitals in " + sposet_name +
" on the grid" << std::endl;
343 std::vector<int>& sposet_inds = (*sposet_indices)[i];
345 int nspo = sposet_inds.size();
367 while (bstart < nspo)
370 app_log() <<
" evaluating orbital batch " << bstart <<
" to " << bend <<
" out of " << nspo << std::endl;
371 for (
int p = 0; p <
npoints; ++p)
377 for (
int b = bstart, ib = 0; b < bend; ++b, ++ib)
383 for (
int b = bstart, ib = 0; b < bend; ++b, ++ib)
385 for (
int b = bstart, ib = 0; b < bend; ++b, ++ib)
387 for (
int b = bstart, ib = 0; b < bend; ++b, ++ib)
393 app_log() <<
" writing all orbitals in the batch" << std::endl;
394 for (
int b = bstart, ib = 0; b < bend; ++b, ++ib)
397 for (
int p = 0; p <
npoints; ++p)
405 for (
int b = bstart, ib = 0; b < bend; ++b, ++ib)
407 for (
int d = 0; d <
DIM; ++d)
409 for (
int p = 0; p <
npoints; ++p)
415 for (
int b = bstart, ib = 0; b < bend; ++b, ++ib)
417 for (
int p = 0; p <
npoints; ++p)
429 app_log() <<
"OrbitalImages::evaluate orbital images written successfully, exiting.\n" << std::endl;
430 APP_ABORT(
" Not a fatal error, just exiting.");
442 std::vector<ValueType>& orb,
455 std::vector<ValueType>& orb,
465 std::array<char, 100> filename;
467 if (derivative_type ==
value_d)
470 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d.xsf", sponame.c_str(), index);
472 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_imag.xsf", sponame.c_str(), index);
474 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_abs.xsf", sponame.c_str(), index);
476 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_abs2.xsf", sponame.c_str(), index);
481 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_grad%1d.xsf", sponame.c_str(), index,
484 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_grad%1d_imag.xsf", sponame.c_str(),
487 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_grad%1d_abs.xsf", sponame.c_str(),
490 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_grad%1d_abs2.xsf", sponame.c_str(),
496 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_lap.xsf", sponame.c_str(), index);
499 std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_lap_imag.xsf", sponame.c_str(), index);
501 file_len = std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_lap_abs.xsf", sponame.c_str(), index);
504 std::snprintf(filename.data(), filename.size(),
"%s_orbital_%04d_lap_abs2.xsf", sponame.c_str(), index);
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;
518 file.open(output_name, std::ios::out | std::ios::trunc);
520 APP_ABORT(
"OrbitalImages::write_orbital\n failed to open file for output: " + output_name);
524 file << std::scientific;
531 file <<
" CRYSTAL" << std::endl;
532 file <<
" PRIMVEC" << std::endl;
533 for (
int i = 0; i <
DIM; ++i)
536 for (
int d = 0; d <
DIM; ++d)
540 file <<
" PRIMCOORD" << std::endl;
541 file <<
" " << natoms <<
" 1" << std::endl;
542 for (
int i = 0; i < natoms; ++i)
545 for (
int d = 0; d <
DIM; ++d)
549 file <<
" BEGIN_BLOCK_DATAGRID_3D" << std::endl;
550 file <<
" orbital " << index << std::endl;
551 file <<
" DATAGRID_3D_ORBITAL" << std::endl;
553 for (
int d = 0; d <
DIM; ++d)
554 file <<
" " <<
grid[d];
557 for (
int d = 0; d <
DIM; ++d)
560 for (
int i = 0; i <
DIM; ++i)
563 for (
int d = 0; d <
DIM; ++d)
569 for (
int p = 0; p <
npoints; ++p)
571 file <<
" " <<
real(orb[p]);
572 if ((p + 1) % columns == 0)
573 file << std::endl <<
" ";
576 for (
int p = 0; p <
npoints; ++p)
578 file <<
" " <<
imag(orb[p]);
579 if ((p + 1) % columns == 0)
580 file << std::endl <<
" ";
583 for (
int p = 0; p <
npoints; ++p)
586 if ((p + 1) % columns == 0)
587 file << std::endl <<
" ";
590 for (
int p = 0; p <
npoints; ++p)
593 if ((p + 1) % columns == 0)
594 file << std::endl <<
" ";
597 file <<
" END_DATAGRID_3D" << std::endl;
598 file <<
" END_BLOCK_DATAGRID_3D" << std::endl;
void set(const Tensor< TT, D > &lat)
set the lattice vector from the command-line options
base class for Single-particle orbital sets
a class that defines a supercell in D-dimensional Euclean space.
OrbitalImages(ParticleSet &P, const PSPool &PSP, Communicate *mpicomm, const SPOMap &spomap)
SingleParticlePos Center
Center of the cell sum(Rv[i])/2.
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
helper functions for EinsplineSetBuilder
int rank() const
return the rank
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
derivative_types_enum
derivative types
const PSPool & psetpool
at put() ion particleset is obtained from ParticleSetPool
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
size_t getTotalNum() const
void convert(const PL &lat, const PV &pin, PV &pout)
bool put(xmlNodePtr cur)
assign attributes to the set
std::vector< std::string > sposet_names
names of sposets to evaluate
std::vector< std::unique_ptr< SPOSet > > sposets
sposets obtained by name from SPOMap
float real(const float &c)
real part of a scalar. Cannot be replaced by std::real due to AFQMC specific needs.
int size() const
return the size of the orbital set Ye: this needs to be replaced by getOrbitalSetSize(); ...
void resize(const std::array< SIZET, D > &dims)
Resize the container.
std::map< std::string, const std::unique_ptr< ParticleSet > > PSPool
Array< ValueType, 2 > batch_laplacians
temporary array to hold laplacians of a batch of orbitals at all grid points
TinyVector< SingleParticlePos, D > Rv
Real-space unit vectors.
Wrapping information on parallelism.
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
virtual void evaluateValue(const ParticleSet &P, int iat, ValueVector &psi)=0
evaluate the values of this single-particle orbital set
omp_int_t omp_get_thread_num()
std::string name_
name of this object
Specialized paritlce class for atomistic simulations.
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
real convert(real value, units units_in, units units_out)
PosType corner
location of cell corner, positions in the cell are corner+uvec*cell
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
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
void report(const std::string &pad)
write brief report of configuration data
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
class to handle a set of attributes of an xmlNode
void rejectMove(Index_t iat)
reject a proposed move in regular mode
const std::shared_ptr< std::vector< std::vector< int > > > sposet_indices
indices of orbitals within each sposet to evaluate
virtual void evaluateVGL(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi)=0
evaluate the values, gradients and laplacians of this single-particle orbital set ...
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)
"Estimator" to produce files for orbital plotting.
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
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's value with the first "element" in the "string" returned by XMLNodeString{cur}.
An abstract class for Local Energy operators.
FullPrecRealType Return_t
type of return value of evaluate
const SPOMap & spomap_
reference to the sposet_builder_factory
Class to represent a many-body trial wave function.
void makeMove(Index_t iat, const SingleParticlePos &displ, bool maybe_accept=true)
move the iat-th particle to active_pos_
const auto & getLattice() const
Communicate * comm
mpi communicator
const std::string & species_from_index(int i)
get species name of particle i
ParticleSet * Peln
electron particleset
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.
double B(double x, int k, int i, const std::vector< double > &t)
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
std::unique_ptr< OperatorBase > makeClone(ParticleSet &P, TrialWaveFunction &psi) final
QMCTraits::FullPrecRealType value_type
value_types_enum
options for orbital value to write
Return_t evaluate(ParticleSet &P) override
hijack estimator evaluate to evaluate and write all orbitals
bool derivatives
write out derivatives in addition to values
bool put(xmlNodePtr cur) override
read xml input