Loading...
Searching...
No Matches
AMS_IO Class Reference

#include <AMS_IO.h>

Inheritance diagram for AMS_IO:

Public Member Functions

 AMS_IO (const Parameters &p)
 ~AMS_IO ()
void initialize ()
void cleanMemory (void)
void force (long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box)
Public Member Functions inherited from eonc::Potential
 Potential (PotType a_ptype)
 Potential (PotType a_ptype, const Parameters &)
 Potential (const Parameters &a_params)
virtual ~Potential ()
std::tuple< double, AtomMatrixget_ef (const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
PotType getType () const
virtual bool isSurrogate () const noexcept
 Whether this is a surrogate (GP) potential.
virtual bool requiresIsolatedMoleculeLayout () const noexcept
 True for molecular QM / non-PBC backends (NWChem socket, ASE ORCA/NWChem, …).
virtual bool isThreadSafe () const noexcept
 Whether this potential's force() can be called from multiple threads on the SAME instance.
virtual bool isSharedInstanceThreadSafe () const noexcept
 Conservative gate for sharing one Potential instance across threads.
virtual bool needsPerImageInstance () const noexcept
 Whether NEB should create separate Potential instances per image for true parallel force evaluation.
virtual bool supportsBatchEvaluation () const noexcept
 Whether this potential supports batched evaluation of N systems in a single call.
virtual void forceBatch (long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes)
 Evaluate forces for N systems in a single call.

Private Member Functions

void passToSystem (long N, const double *R, const int *atomicNrs, const double *box)
void recieveFromSystem (long N, double *F, double *U)

Private Attributes

std::string engine
std::string model
std::string forcefield
std::string xc

Additional Inherited Members

Public Attributes inherited from eonc::Potential
std::atomic< size_t > forceCallCounter
Protected Attributes inherited from eonc::Potential
PotType ptype

Detailed Description

Definition at line 19 of file AMS_IO.h.

Constructor & Destructor Documentation

◆ AMS_IO()

AMS_IO::AMS_IO ( const Parameters & p)

Definition at line 48 of file AMS_IO.cpp.

53 xc = p.ams_options.xc;
54 return;
55}
std::string forcefield
Definition AMS_IO.h:37
std::string model
Definition AMS_IO.h:36
std::string engine
Definition AMS_IO.h:35
std::string xc
Definition AMS_IO.h:38
struct eonc::Parameters::ams_options_t ams_options
Potential(PotType a_ptype)
Definition Potential.h:35

◆ ~AMS_IO()

AMS_IO::~AMS_IO ( )

Definition at line 59 of file AMS_IO.cpp.

59{ cleanMemory(); }
void cleanMemory(void)
Definition AMS_IO.cpp:57

Member Function Documentation

◆ cleanMemory()

void AMS_IO::cleanMemory ( void )

Definition at line 57 of file AMS_IO.cpp.

57{ return; }

◆ force()

void AMS_IO::force ( long N,
const double * R,
const int * atomicNrs,
double * F,
double * U,
double * variance,
const double * box )
virtual

Implements eonc::Potential.

Definition at line 101 of file AMS_IO.cpp.

102 {
103 variance = nullptr;
104 passToSystem(N, R, atomicNrs, box);
105 // Run a single point AMS_IO calculation and write the results into
106 // ams_output
107 eonc::pot::runOrThrow(kRunCommand);
108 recieveFromSystem(N, F, U);
109 return;
110}
void recieveFromSystem(long N, double *F, double *U)
Definition AMS_IO.cpp:176
void passToSystem(long N, const double *R, const int *atomicNrs, const double *box)
Definition AMS_IO.cpp:112
void runOrThrow(const std::string &command)
Run a shell command, throwing when it does not succeed.

◆ initialize()

void AMS_IO::initialize ( )
inline

Definition at line 24 of file AMS_IO.h.

24{};

◆ passToSystem()

void AMS_IO::passToSystem ( long N,
const double * R,
const int * atomicNrs,
const double * box )
private

Definition at line 112 of file AMS_IO.cpp.

115{
116 std::ofstream out(kRunScript, std::ios::trunc);
117 if (!out) {
118 throw std::runtime_error(
119 std::format("Could not open {} for writing", kRunScript));
120 }
121
122 out << "#!/bin/sh\n";
123 out << "ams --delete-old-results <<eor\n";
124 out << "Task SinglePoint\n";
125 out << "System\n";
126 out << " Atoms\n";
127 for (long i = 0; i < N; i++) {
128 out << std::format(" {}\t{:.19f}\t{:.19f}\t{:.19f}\n",
129 atomicNumber2symbol(atomicNrs[i]), R[i * 3 + 0],
130 R[i * 3 + 1], R[i * 3 + 2]);
131 }
132 out << " End\n";
133 if (!model.empty() || !forcefield.empty()) {
134 out << " Lattice\n";
135 for (int i = 0; i < 3; i++) {
136 out << std::format(" {:.19f}\t{:.19f}\t{:.19f}\n", box[i * 3 + 0],
137 box[i * 3 + 1], box[i * 3 + 2]);
138 }
139 out << " End\n";
140 }
141 out << "End\n";
142 out << std::format("Engine {}\n", engine);
143 if (!forcefield.empty()) {
144 out << std::format(" Forcefield {}\n", forcefield);
145 }
146 if (!model.empty()) {
147 out << std::format(" Model {}\n", model);
148 }
149 if (!xc.empty()) {
150 out << std::format("xc {}\n", xc);
151 // basis set not specified (default = DZ)
152 out << std::format(" hybrid {}\n", xc);
153 out << "end\n";
154 }
155 out << "EndEngine\n";
156 out << "Properties\n";
157 out << " Gradients\n";
158 out << "End\n";
159 out << "eor";
160
161 out.close();
162 if (!out) {
163 throw std::runtime_error(
164 std::format("Could not write the AMS input to {}", kRunScript));
165 }
166
167#ifndef _WIN32
168 if (chmod(kRunScript, S_IRWXU) != 0) {
169 throw std::runtime_error(
170 std::format("Could not make {} executable", kRunScript));
171 }
172#endif
173 return;
174}

◆ recieveFromSystem()

void AMS_IO::recieveFromSystem ( long N,
double * F,
double * U )
private

Definition at line 176 of file AMS_IO.cpp.

176 {
177 std::ifstream in(kOutputFile);
178 if (!in) {
179 throw std::runtime_error(
180 std::format("Could not open {}; AMS left no output", kOutputFile));
181 }
182
183 bool haveEnergy = false;
184 bool haveGradients = false;
185 std::string line;
186
187 while (std::getline(in, line)) {
188
189 if (line == kEnergyMarker) { // Finding the Energy in the output file
190 std::string junk;
191 if (!(in >> junk >> junk >> junk >> *U)) {
192 throw std::runtime_error(
193 std::format("Could not read the energy following \"{}\" in {}",
194 kEnergyMarker, kOutputFile));
195 }
196 *U = *U * kHartreeToEv; // Energy in hartree to eV
197 haveEnergy = true;
198 }
199
200 if (line == kGradientMarker) { // Finding the forces
201 double index;
202 std::string symbol;
203 for (long i = 0; i < N; i++) {
204 if (!(in >> index >> symbol >> F[i * 3 + 0] >> F[i * 3 + 1] >>
205 F[i * 3 + 2])) {
206 throw std::runtime_error(
207 std::format("{} holds gradients for {} atoms, expected {}",
208 kOutputFile, i, N));
209 }
210 // AMS_IO gives gradients, not forces, hence the change.
211 F[i * 3 + 0] = -F[i * 3 + 0];
212 F[i * 3 + 1] = -F[i * 3 + 1];
213 F[i * 3 + 2] = -F[i * 3 + 2];
214 }
215 haveGradients = true;
216 }
217 }
218
219 if (!haveEnergy || !haveGradients) {
220 throw std::runtime_error(std::format(
221 "{} holds no {}", kOutputFile,
222 !haveEnergy
223 ? (!haveGradients ? "energy and no gradient block" : "energy")
224 : "gradient block"));
225 }
226
227 for (long i = 0; i < 3 * N; i++) {
228 F[i] = F[i] * kHartreeBohrToEvAngstrom; // Forces from hartree/bohr to
229 // eV/Angstrom
230 }
231 return;
232}

Member Data Documentation

◆ engine

std::string AMS_IO::engine
private

Definition at line 35 of file AMS_IO.h.

◆ forcefield

std::string AMS_IO::forcefield
private

Definition at line 37 of file AMS_IO.h.

◆ model

std::string AMS_IO::model
private

Definition at line 36 of file AMS_IO.h.

◆ xc

std::string AMS_IO::xc
private

Definition at line 38 of file AMS_IO.h.


The documentation for this class was generated from the following files:
  • /home/runner/work/eOn/eOn/include/eon/potentials/AMS_IO/AMS_IO.h
  • /home/runner/work/eOn/eOn/client/potentials/AMS_IO/AMS_IO.cpp