Loading...
Searching...
No Matches
eonc::TestJob Class Reference

#include <TestJob.h>

Inheritance diagram for eonc::TestJob:

Public Member Functions

 TestJob (std::unique_ptr< Parameters > params)
 ~TestJob (void)=default
std::vector< std::string > run (void)
 Virtual run; used solely for dynamic dispatch.
Public Member Functions inherited from eonc::Job
 Job (std::unique_ptr< Parameters > parameters)
 Job (std::shared_ptr< Potential > potPassed, const Parameters &parameters)
virtual ~Job ()=default
JobType getType ()

Private Member Functions

void checkFullSearch (void)
void checkPotentials (void)
double getEnergyDiff (std::string potTag, double refEnergy)
double getForceDiff (std::string potTag, double refForce)

Private Attributes

double tolerance {0.0}

Additional Inherited Members

Protected Attributes inherited from eonc::Job
JobType jtype
Parameters params
std::shared_ptr< Potentialpot

Detailed Description

Definition at line 20 of file TestJob.h.

Constructor & Destructor Documentation

◆ TestJob()

eonc::TestJob::TestJob ( std::unique_ptr< Parameters > params)
inline

Definition at line 22 of file TestJob.h.

23 : Job(std::move(params)),
24 tolerance{0.01} {}
Job(std::unique_ptr< Parameters > parameters)
Definition Job.h:58
Parameters params
Definition Job.h:54
double tolerance
Definition TestJob.h:29

◆ ~TestJob()

eonc::TestJob::~TestJob ( void )
default

Member Function Documentation

◆ checkFullSearch()

void TestJob::checkFullSearch ( void )
private

Definition at line 29 of file TestJob.cpp.

29 {
30 printf("\n---Beginning tests of saddle point search---\n");
31 printf("Checks the potential energies of located configurations.\n");
32 printf("Reported as OK if within a tolerance of: %f\n", tolerance);
33
34 // long status;
35 bool ok = 1;
36 double diffM1, diffM2, diffSP;
37
38 string reactantFilename("reactant_test.con");
39 string displacementFilename("displacement_test.con");
40 string modeFilename("mode_test.dat");
41
42 params.potential_options.potential = "emt";
43
44 auto initial = std::make_unique<Matter>(pot, params);
45 // displacement = std::make_unique<Matter>(pot, params);
46 auto saddle = std::make_unique<Matter>(pot, params);
47 auto min1 = std::make_unique<Matter>(pot, params);
48 auto min2 = std::make_unique<Matter>(pot, params);
49 auto matterTemp = std::make_unique<Matter>(pot, params);
50
51 if (!eonc::io::io_ok(saddle->con2matter(displacementFilename))) {
52 throw std::runtime_error("failed to load " + displacementFilename);
53 }
54 if (!eonc::io::io_ok(initial->con2matter(reactantFilename))) {
55 throw std::runtime_error("failed to load " + reactantFilename);
56 }
57 *min1 = *min2 = *initial;
58
59 printf("\n---Output for saddle point search start---\n");
60 // saddleSearch = new SaddleSearch();
61 // saddleSearch->initialize(initial, saddle, params);
62 // saddleSearch->loadMode(mode_passed);
63 // status = saddleSearch->locate();
64 printf("---Output for saddle point search end---\n\n");
65
66 printf("---Output relax from saddle point search start---\n");
67 // relax from the saddle point located
68
69 // AtomMatrix posSaddle = saddleSearch->getSaddlePositions();
70 AtomMatrix displacedPos;
71
72 *min1 = *saddle;
73 // XXX: the distance displaced from the saddle should be a parameter
74 // displacedPos = posSaddle - saddleSearch->getEigenMode() * 0.2;
75 min1->setPositions(displacedPos);
76 // ConjugateGradients cgMin1(min1, params);
77 // cgMin1.fullRelax();
78 // fCallsMin += cgMin1.totalForceCalls;
79
80 *min2 = *saddle;
81 // displacedPos = posSaddle + saddleSearch->getEigenMode() * 0.2;
82 // min2->setPositions(displacedPos);
83 // ConjugateGradients cgMin2(min2, params);
84 // cgMin2.fullRelax();
85 // fCallsMin += cgMin2.totalForceCalls;
86
87 // If min2 corresponds to initial state swap min1 && min2
88 if (!initial->compare(min1) && initial->compare(min2)) {
89 *matterTemp = *min1;
90 *min1 = *min2;
91 *min2 = *matterTemp;
92 }
93 printf("---Output relax from saddle point search end---\n");
94
95 // checking the energies of the obtained configurations
96 diffM1 = std::abs(min1->getPotentialEnergy() - 45.737426);
97 diffM2 = std::abs(min2->getPotentialEnergy() - 45.737433);
98 diffSP = std::abs(saddle->getPotentialEnergy() - 46.284511);
99
100 if ((diffM1 < tolerance) and (diffM2 < tolerance) and (diffSP < tolerance)) {
101 ok *= 1;
102 printf("OK: Saddle search structural energies\n");
103 } else {
104 if (tolerance < diffSP) {
105 ok *= 0;
106 printf("WARNING: Saddle point not within energy tolerance: %f\n", diffSP);
107 }
108 if (tolerance < diffM2) {
109 ok *= 0;
110 printf("WARNING: Minimum 2 not within energy tolerance: %f\n", diffM2);
111 }
112 if (tolerance < diffM1) {
113 ok *= 0;
114 printf("WARNING: Minimum 1 not within energy tolerance: %f\n", diffM2);
115 }
116 }
117
118 // checking the structures of the obtained configurations
119 diffM1 = std::abs((min1->getPositions()).row(384).norm() - 19.123375);
120 diffM2 = std::abs((min2->getPositions()).row(384).norm() - 19.527995);
121 diffSP = std::abs((saddle->getPositions()).row(384).norm() - 19.026709);
122
123 if ((diffM1 < tolerance) and (diffM2 < tolerance) and (diffSP < tolerance)) {
124 ok *= 1;
125 printf("OK: Saddle search, adatom positions\n");
126 } else {
127 if (tolerance < diffSP) {
128 ok *= 0;
129 printf(
130 "WARNING: Saddle point, adatom not within position tolerance: %f\n",
131 diffSP);
132 }
133 if (tolerance < diffM2) {
134 ok *= 0;
135 printf("WARNING: Minimum 2, adatom not within position tolerance: %f\n",
136 diffM2);
137 }
138 if (tolerance < diffM1) {
139 ok *= 0;
140 printf("WARNING: Minimum 1, adatom not within position tolerance: %f\n",
141 diffM1);
142 }
143 }
144
145 if (ok) {
146 printf("Saddle search tests all good\n");
147 } else {
148 printf("Saddle search tests there were WARNINGS\n");
149 }
150 printf("SP done\n");
151
152 // unique_ptrs clean up automatically
153 return;
154}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
std::shared_ptr< Potential > pot
Definition Job.h:55
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38

◆ checkPotentials()

void TestJob::checkPotentials ( void )
private

Definition at line 155 of file TestJob.cpp.

155 {
156 double energyDiff;
157 double forceDiff;
158
159 printf("\n---Beginning tests of potentials---\n");
160 printf("Checks the potential energy and the max force.\n");
161 printf("Reported as OK if within a tolerance of: %f\n\n", tolerance);
162
163 energyDiff = getEnergyDiff(Potential::POT_LJ, -1475.984331);
164 if (std::abs(energyDiff) > tolerance) {
165 printf("WARNING: LJ energy difference: %f\n", energyDiff);
166 } else {
167 forceDiff = getForceDiff(Potential::POT_LJ, 2.007213);
168 if (std::abs(forceDiff) > tolerance) {
169 printf("WARNING: LJ force difference: %f\n", forceDiff);
170 } else {
171 printf("OK: LJ\n");
172 }
173 }
174
175 energyDiff = getEnergyDiff(Potential::POT_EMT, 46.086312);
176 if (std::abs(energyDiff) > tolerance) {
177 printf("WARNING: EMT energy difference: %f\n", energyDiff);
178 } else {
179 forceDiff = getForceDiff(Potential::POT_EMT, 0.357493);
180 if (std::abs(forceDiff) > tolerance) {
181 printf("WARNING: EMT force difference: %f\n", forceDiff);
182 } else {
183 printf("OK: EMT\n");
184 }
185 }
186
187 energyDiff = getEnergyDiff(Potential::POT_EDIP, -1033.250950);
188 if (std::abs(energyDiff) > tolerance) {
189 printf("WARNING: EDIP energy difference: %f\n", energyDiff);
190 } else {
191 forceDiff = getForceDiff(Potential::POT_EDIP, 7.080115);
192 if (std::abs(forceDiff) > tolerance) {
193 printf("WARNING: EDIP force difference: %f\n", forceDiff);
194 } else {
195 printf("OK: EDIP\n");
196 }
197 }
198
199 energyDiff = getEnergyDiff(Potential::POT_TERSOFF_SI, -1035.809985);
200 if (std::abs(energyDiff) > tolerance) {
201 printf("WARNING: Tersoff energy difference: %f\n", energyDiff);
202 } else {
203 forceDiff = getForceDiff(Potential::POT_TERSOFF_SI, 11.145002);
204 if (std::abs(forceDiff) > tolerance) {
205 printf("WARNING: Tersoff force difference: %f\n", forceDiff);
206 } else {
207 printf("OK: Tersoff\n");
208 }
209 }
210
211 energyDiff = getEnergyDiff(Potential::POT_SW_SI, -1449.795645);
212 if (std::abs(energyDiff) > tolerance) {
213 printf("WARNING: SW energy difference: %f\n", energyDiff);
214 } else {
215 forceDiff = getForceDiff(Potential::POT_SW_SI, 2.530904);
216 if (std::abs(forceDiff) > tolerance) {
217 printf("WARNING: SW force difference: %f\n", forceDiff);
218 } else {
219 printf("OK: SW\n");
220 }
221 }
222
223 energyDiff = getEnergyDiff(Potential::POT_LENOSKY_SI, -1410.679106);
224 if (std::abs(energyDiff) > tolerance) {
225 printf("Lenosky energy difference: %f\n", energyDiff);
226 } else {
227 forceDiff = getForceDiff(Potential::POT_LENOSKY_SI, 2.320168);
228 if (std::abs(forceDiff) > tolerance) {
229 printf("Lenosky force difference: %f\n", forceDiff);
230 } else {
231 printf("OK: Lenosky\n");
232 }
233 }
234
235 energyDiff = getEnergyDiff(Potential::POT_EAM_AL, -1206.825825);
236 if (std::abs(energyDiff) > tolerance) {
237 printf("WARNING: Aluminum energy difference: %f\n", energyDiff);
238 } else {
239 forceDiff = getForceDiff(Potential::POT_EAM_AL, 0.000246);
240 if (std::abs(forceDiff) > tolerance) {
241 printf("WARNING: Aluminum force difference: %f\n", forceDiff);
242 } else {
243 printf("OK: Aluminum\n");
244 }
245 }
246
247 energyDiff = getEnergyDiff(Potential::POT_QSC, -1232.806318);
248 if (std::abs(energyDiff) > tolerance) {
249 printf("WARNING: QSC energy difference: %f\n", energyDiff);
250 } else {
251 forceDiff = getForceDiff(Potential::POT_QSC, 0.673444);
252 if (std::abs(forceDiff) > tolerance) {
253 printf("WARNING: QSC force difference: %f\n", forceDiff);
254 } else {
255 printf("OK: QSC\n");
256 }
257 }
258
259 energyDiff = getEnergyDiff(Potential::POT_TIP4P, 4063.865115);
260 if (std::abs(energyDiff) > tolerance) {
261 printf("WARNING: TIP4P energy difference: %f\n", energyDiff);
262 } else {
263 forceDiff = getForceDiff(Potential::POT_TIP4P, 73.655248);
264 if (std::abs(forceDiff) > tolerance) {
265 printf("WARNING: TIP4P force difference: %f\n", forceDiff);
266 } else {
267 printf("OK: TIP4P\n");
268 }
269 }
270}
double getEnergyDiff(std::string potTag, double refEnergy)
Definition TestJob.cpp:272
double getForceDiff(std::string potTag, double refForce)
Definition TestJob.cpp:282

◆ getEnergyDiff()

double TestJob::getEnergyDiff ( std::string potTag,
double refEnergy )
private

Definition at line 272 of file TestJob.cpp.

272 {
273 string posFilename("pos_test.con");
274 params.potential_options.potential = pot;
275 auto pos = std::make_unique<Matter>(pot, params);
276 if (!eonc::io::io_ok(pos->con2matter(posFilename))) {
277 throw std::runtime_error("failed to load " + posFilename);
278 }
279 return pos->getPotentialEnergy() - refEnergy;
280}

◆ getForceDiff()

double TestJob::getForceDiff ( std::string potTag,
double refForce )
private

Definition at line 282 of file TestJob.cpp.

282 {
283 std::string posFilename("pos_test.con");
284 params.potential_options.potential = pot;
285 auto pos = std::make_unique<Matter>(pot, params);
286 if (!eonc::io::io_ok(pos->con2matter(posFilename))) {
287 throw std::runtime_error("failed to load " + posFilename);
288 }
289 return pos->maxForce() - refForce;
290}

◆ run()

std::vector< std::string > TestJob::run ( void )
virtual

Virtual run; used solely for dynamic dispatch.

Implements eonc::Job.

Definition at line 22 of file TestJob.cpp.

22 {
25 std::vector<std::string> empty;
26 return empty;
27}
void checkFullSearch(void)
Definition TestJob.cpp:29
void checkPotentials(void)
Definition TestJob.cpp:155

Member Data Documentation

◆ tolerance

double eonc::TestJob::tolerance {0.0}
private

Definition at line 29 of file TestJob.h.

29{0.0};

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