Loading...
Searching...
No Matches
AtomicGPDimer.cpp
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12// An interface to the GPDimer library
13
14#include "eon/AtomicGPDimer.h"
15#include "eon/GPRHelpers.h"
16#include "eon/HelperFunctions.h"
17#include "eon/fpe_handler.h"
18#include <cassert>
19#include <cmath>
20#include <cstring>
21
22#include "subprojects/gpr_optim/gpr/AtomicDimer.h"
23#include "subprojects/gpr_optim/gpr/auxiliary/ProblemSetUp.h"
24#include "subprojects/gpr_optim/structures/Structures.h"
25
26namespace {
27
28// AtomMatrix is row-major N×3; gpr::Coord is row-major 1×(3N) with the same
29// flat packing [x0,y0,z0,x1,...].
30void copyAtomMatrixToCoord(const AtomMatrix &src, gpr::Coord &dst) {
31 dst.resize(1, static_cast<Eigen::Index>(src.size()));
32 if (src.size() > 0) {
33 std::memcpy(dst.data(), src.data(),
34 static_cast<size_t>(src.size()) * sizeof(double));
35 }
36}
37
38} // namespace
39
40const char AtomicGPDimer::OPT_SCG[] = "scg";
41const char AtomicGPDimer::OPT_LBFGS[] = "lbfgs";
42
43AtomicGPDimer::AtomicGPDimer(std::shared_ptr<Matter> matter,
44 const Parameters &params,
45 std::shared_ptr<Potential> pot)
47 matterCenter = std::make_shared<Matter>(pot, params);
48 *matterCenter = *matter;
50 const Matrix3d cell = matter->getCell();
51 for (int i = 0; i < 9; i++) {
52 p.cell_dimensions.value[i] = cell.data()[i];
53 }
54}
55
56void AtomicGPDimer::compute(std::shared_ptr<Matter> matter,
57 AtomMatrix initialDirectionAtomMatrix) {
59 copyAtomMatrixToCoord(matterCenter->getPositionsFree(), R_init);
60 init_middle_point.clear();
62 init_observations.clear();
63 problem_setup.activateFrozenAtoms(
64 R_init, params.gpr_dimer_options.active_radius, atoms_config);
65 AtomMatrix freeOrient(matterCenter->numberOfFreeAtoms(), 3);
66 int j = 0;
67 for (int i = 0; i < matterCenter->numberOfAtoms(); i++) {
68 if (!matterCenter->getFixed(i)) {
69 freeOrient.row(j) = initialDirectionAtomMatrix.row(i);
70 j++;
71 if (j == matterCenter->numberOfFreeAtoms()) {
72 break;
73 }
74 }
75 }
76 copyAtomMatrixToCoord(freeOrient, orient_init);
79
80 auto potential = eonc::helpers::makePotential(params);
81 pot::PotentialWrapper wrapper(
82 [&potential](long N, const double *R, const int *atomicNrs, double *F,
83 double *U, double *variance, const double *box) {
84 potential->force(N, R, atomicNrs, F, U, variance, box);
85 });
87 fpeh.eat_fpe();
88 atomic_dimer.execute(wrapper);
89 fpeh.restore_fpe();
90 // Forcefully set the right positions
91 matter->setPositionsFreeV(atomic_dimer.getFinalCoordOfMidPoint());
92 this->totalIterations = atomic_dimer.getIterations();
93 this->totalForceCalls = atomic_dimer.getTotalForceCalls();
94 pot->forceCallCounter = atomic_dimer.getTotalForceCalls();
95 return;
96}
97
99 return atomic_dimer.getFinalCurvature();
100}
101
103 const gpr::Coord &orient = atomic_dimer.getFinalOrientation();
104 long nFree = matterCenter->numberOfFreeAtoms();
105 return Eigen::Map<const AtomMatrix>(orient.data(), nFree, 3);
106}
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Definition Eigen.h:35
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
static const char OPT_LBFGS[]
static const char OPT_SCG[]
AtomicGPDimer(std::shared_ptr< Matter > matter, const Parameters &params, std::shared_ptr< Potential > pot)
gpr::AtomsConfiguration atoms_config
gpr::Observation init_observations
std::shared_ptr< Matter > matterCenter
gpr::InputParameters p
AtomMatrix getEigenvector()
gpr::Observation init_middle_point
void compute(std::shared_ptr< Matter > matter, AtomMatrix initialDirection)
atmd::AtomicDimer atomic_dimer
aux::ProblemSetUp problem_setup
const Parameters & params
std::shared_ptr< Potential > pot
LowestEigenmode(std::shared_ptr< Potential > potPassed, const Parameters &parameters)
gpr::InputParameters eon_parameters_to_gpr(const Parameters &parameters)
Create a parameters object for gpr_dimer.
gpr::AtomsConfiguration eon_matter_to_atmconf(Matter *matter)
Create a configuration of atoms for gpr_dimer.
std::shared_ptr< Potential > makePotential(const Parameters &params)