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

#include <AMS_IO.h>

Inheritance diagram for AMS_IO:

Public Member Functions

 AMS_IO (const eonc::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)
 Production default: construction-scope registry, else PotRegistry::get().
 Potential (PotType a_ptype, IPotRegistry &registry)
 Test seam: injected registry, no process-default get() counters.
 Potential (PotType a_ptype, const Parameters &p)
 Potential (const Parameters &a_params)
virtual ~Potential ()
void force (std::span< const double > positions, std::span< const int > atomicNrs, std::span< double > forces, double *energy, double *variance, std::span< const double > box)
 C++ call site: size-checked view over the raw FFI force().
virtual void setFixedMask (long nAtoms, const double *isFixed)
 Optional frozen-atom mask (nAtoms*3, 1.0 = fixed).
std::tuple< double, AtomMatrix > get_ef (const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
PotType getType () const
virtual double finiteCutoff () const noexcept
 Finite interaction range in position length units.
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 unsigned layoutFlags () const noexcept
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 std::shared_ptr< Potential > clonePotential () const
 Independent instance that does not reload from disk.
virtual bool supportsBatchEvaluation () const noexcept
 Whether this potential supports batched evaluation of N systems in a single call.
virtual bool computesStress () const noexcept
 True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance.
virtual Matrix3d cauchyStress () const
 Cauchy stress in eV/Angstrom^3.
virtual void forceBatchOwned (long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes, const long *owners)
 Evaluate forces for 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)

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 Types inherited from eonc::Potential
enum class  PotLayout : unsigned { InProcess = 1u << 0 , NeedsWorkingDirectory = 1u << 1 , Subprocess = 1u << 2 }
 How the pot is executed. Combine with bitwise or. More...
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 eonc::Parameters & p)

Definition at line 51 of file AMS_IO.cpp.

52 : eonc::Potential(eonc::PotType::AMS_IO, p) {
56 xc = p.ams_options().xc;
57 return;
58}
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
const ams_options_t & ams_options() const

◆ ~AMS_IO()

AMS_IO::~AMS_IO ( )

Definition at line 62 of file AMS_IO.cpp.

62{ cleanMemory(); }
void cleanMemory(void)
Definition AMS_IO.cpp:60

Member Function Documentation

◆ cleanMemory()

void AMS_IO::cleanMemory ( void )

Definition at line 60 of file AMS_IO.cpp.

60{ 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 75 of file AMS_IO.cpp.

76 {
77 variance = nullptr;
78 passToSystem(N, R, atomicNrs, box);
79 // Run a single point AMS_IO calculation and write the results into
80 // ams_output
81 eonc::pot::runOrThrow(kRunCommand);
82 recieveFromSystem(N, F, U);
83 return;
84}
void recieveFromSystem(long N, double *F, double *U)
Definition AMS_IO.cpp:150
void passToSystem(long N, const double *R, const int *atomicNrs, const double *box)
Definition AMS_IO.cpp:86
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 86 of file AMS_IO.cpp.

89{
90 std::ofstream out(kRunScript, std::ios::trunc);
91 if (!out) {
92 throw std::runtime_error(
93 std::format("Could not open {} for writing", kRunScript));
94 }
95
96 out << "#!/bin/sh\n";
97 out << "ams --delete-old-results <<eor\n";
98 out << "Task SinglePoint\n";
99 out << "System\n";
100 out << " Atoms\n";
101 for (long i = 0; i < N; i++) {
102 out << std::format(" {}\t{:.19f}\t{:.19f}\t{:.19f}\n",
103 symbol_for_z(atomicNrs[i]), R[i * 3 + 0], R[i * 3 + 1],
104 R[i * 3 + 2]);
105 }
106 out << " End\n";
107 if (!model.empty() || !forcefield.empty()) {
108 out << " Lattice\n";
109 for (int i = 0; i < 3; i++) {
110 out << std::format(" {:.19f}\t{:.19f}\t{:.19f}\n", box[i * 3 + 0],
111 box[i * 3 + 1], box[i * 3 + 2]);
112 }
113 out << " End\n";
114 }
115 out << "End\n";
116 out << std::format("Engine {}\n", engine);
117 if (!forcefield.empty()) {
118 out << std::format(" Forcefield {}\n", forcefield);
119 }
120 if (!model.empty()) {
121 out << std::format(" Model {}\n", model);
122 }
123 if (!xc.empty()) {
124 out << std::format("xc {}\n", xc);
125 // basis set not specified (default = DZ)
126 out << std::format(" hybrid {}\n", xc);
127 out << "end\n";
128 }
129 out << "EndEngine\n";
130 out << "Properties\n";
131 out << " Gradients\n";
132 out << "End\n";
133 out << "eor";
134
135 out.close();
136 if (!out) {
137 throw std::runtime_error(
138 std::format("Could not write the AMS input to {}", kRunScript));
139 }
140
141#ifndef _WIN32
142 if (chmod(kRunScript, S_IRWXU) != 0) {
143 throw std::runtime_error(
144 std::format("Could not make {} executable", kRunScript));
145 }
146#endif
147 return;
148}

◆ recieveFromSystem()

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

Definition at line 150 of file AMS_IO.cpp.

150 {
151 std::ifstream in(kOutputFile);
152 if (!in) {
153 throw std::runtime_error(
154 std::format("Could not open {}; AMS left no output", kOutputFile));
155 }
156
157 bool haveEnergy = false;
158 bool haveGradients = false;
159 std::string line;
160
161 while (std::getline(in, line)) {
162
163 if (line == kEnergyMarker) { // Finding the Energy in the output file
164 std::string junk;
165 if (!(in >> junk >> junk >> junk >> *U)) {
166 throw std::runtime_error(
167 std::format("Could not read the energy following \"{}\" in {}",
168 kEnergyMarker, kOutputFile));
169 }
170 *U = *U * kHartreeToEv; // Energy in hartree to eV
171 haveEnergy = true;
172 }
173
174 if (line == kGradientMarker) { // Finding the forces
175 double index;
176 std::string symbol;
177 for (long i = 0; i < N; i++) {
178 if (!(in >> index >> symbol >> F[i * 3 + 0] >> F[i * 3 + 1] >>
179 F[i * 3 + 2])) {
180 throw std::runtime_error(
181 std::format("{} holds gradients for {} atoms, expected {}",
182 kOutputFile, i, N));
183 }
184 // AMS_IO gives gradients, not forces, hence the change.
185 F[i * 3 + 0] = -F[i * 3 + 0];
186 F[i * 3 + 1] = -F[i * 3 + 1];
187 F[i * 3 + 2] = -F[i * 3 + 2];
188 }
189 haveGradients = true;
190 }
191 }
192
193 if (!haveEnergy || !haveGradients) {
194 throw std::runtime_error(std::format(
195 "{} holds no {}", kOutputFile,
196 !haveEnergy
197 ? (!haveGradients ? "energy and no gradient block" : "energy")
198 : "gradient block"));
199 }
200
201 for (long i = 0; i < 3 * N; i++) {
202 F[i] = F[i] * kHartreeBohrToEvAngstrom; // Forces from hartree/bohr to
203 // eV/Angstrom
204 }
205 return;
206}

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