Loading...
Searching...
No Matches
SocketNWChemPot.h
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#pragma once
13
14#include "eon/Potential.h"
15#include <memory>
16#include <string>
17
28public:
29 explicit SocketNWChemPot(const eonc::Parameters &p);
30 ~SocketNWChemPot() override;
31
39 void write_nwchem_template(const std::string &filename, long N,
40 const std::vector<std::string> &atom_symbols);
41
59 void force(long N, const double *R, const int *atomicNrs, double *F,
60 double *U, double *variance, const double *box) override;
61
63 [[nodiscard]] bool requiresIsolatedMoleculeLayout() const noexcept override {
64 return true;
65 }
66 [[nodiscard]] bool isThreadSafe() const noexcept override { return false; }
69 [[nodiscard]] bool needsPerImageInstance() const noexcept override {
70 return false;
71 }
72
73 [[nodiscard]] bool computesStress() const noexcept override {
74 return haveStress_;
75 }
76
77 [[nodiscard]] Matrix3d cauchyStress() const override { return stress_; }
78
79private:
80 // --- Private Methods ---
81 void setup_server();
82 void accept_connection();
83 void drop_connection();
84 void forceOnce(long N, const double *R, const int *atomicNrs, double *F,
85 double *U, double *variance, const double *box);
86 void send_header(const char *msg);
87 void recv_header(char *buffer);
88 void send_exact(const void *buffer, size_t n_bytes);
89 void recv_exact(void *buffer, size_t n_bytes);
90
91 // --- Member Variables ---
92 // Socket configuration
94 // For TCP, the host; for UNIX, the full socket path.
95 std::string server_address;
96 // The original name for the .nwi file.
98 // File containing actual calculation parameters
99 std::string nwchem_settings;
101 // Generate a template input
103
104 // Socket state
105 int listen_fd{-1};
106 int conn_fd{-1};
107 bool is_connected{false};
108
109 // --- Constants for i-PI protocol and unit conversions ---
110 static constexpr int MSG_LEN = 12;
111 // From ASE units, values for eV and Angstrom
112 static constexpr double BOHR_IN_ANGSTROM = 0.529177210903;
113 static constexpr double HARTREE_IN_EV = 27.211386245988;
114
115 Matrix3d stress_{Matrix3d::Zero()};
116 bool haveStress_{false};
117};
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Definition Eigen.h:35
std::string unix_socket_basename
~SocketNWChemPot() override
static constexpr int MSG_LEN
bool computesStress() const noexcept override
True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this ...
bool isThreadSafe() const noexcept override
Whether this potential's force() can be called from multiple threads on the SAME instance.
void send_header(const char *msg)
void recv_exact(void *buffer, size_t n_bytes)
void send_exact(const void *buffer, size_t n_bytes)
std::string server_address
static constexpr double BOHR_IN_ANGSTROM
void recv_header(char *buffer)
static constexpr double HARTREE_IN_EV
Matrix3d cauchyStress() const override
Cauchy stress in eV/Angstrom^3.
void write_nwchem_template(const std::string &filename, long N, const std::vector< std::string > &atom_symbols)
Generates an NWChem input file (.nwi) configured to connect to this server.
std::string nwchem_settings
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
The method called to compute forces and energy.
bool needsPerImageInstance() const noexcept override
One listening socket and one NWChem client.
bool requiresIsolatedMoleculeLayout() const noexcept override
NWChem socket SCF does not support PBC (#188).
SocketNWChemPot(const eonc::Parameters &p)
void forceOnce(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box)