A potential that gets forces and energy from an NWChem server via a socket. More...
#include <SocketNWChemPot.h>
Public Member Functions | |
| SocketNWChemPot (const eonc::Parameters &p) | |
| ~SocketNWChemPot () override | |
| 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. | |
| 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 | requiresIsolatedMoleculeLayout () const noexcept override |
| NWChem socket SCF does not support PBC (#188). | |
| bool | isThreadSafe () const noexcept override |
| Whether this potential's force() can be called from multiple threads on the SAME instance. | |
| bool | needsPerImageInstance () const noexcept override |
| One listening socket and one NWChem client. | |
| bool | computesStress () const noexcept override |
| True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance. | |
| Matrix3d | cauchyStress () const override |
| Cauchy stress in eV/Angstrom^3. | |
| Public Member Functions inherited from eonc::Potential | |
| Potential (PotType a_ptype) | |
| Production default: construction-scope registry, else PotRegistry::get(). | |
| Potential (PotType a_ptype, IPotRegistry ®istry) | |
| 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 unsigned | layoutFlags () const noexcept |
| virtual bool | isSharedInstanceThreadSafe () const noexcept |
| Conservative gate for sharing one Potential instance across threads. | |
| 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 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 | setup_server () |
| void | accept_connection () |
| void | drop_connection () |
| void | forceOnce (long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) |
| void | send_header (const char *msg) |
| void | recv_header (char *buffer) |
| void | send_exact (const void *buffer, size_t n_bytes) |
| void | recv_exact (void *buffer, size_t n_bytes) |
Private Attributes | |
| bool | unix_socket_mode |
| std::string | server_address |
| std::string | unix_socket_basename |
| std::string | nwchem_settings |
| int | port |
| int | mem_in_gb |
| bool | make_template_input |
| int | listen_fd {-1} |
| int | conn_fd {-1} |
| bool | is_connected {false} |
| Matrix3d | stress_ {Matrix3d::Zero()} |
| bool | haveStress_ {false} |
Static Private Attributes | |
| static constexpr int | MSG_LEN = 12 |
| static constexpr double | BOHR_IN_ANGSTROM = 0.529177210903 |
| static constexpr double | HARTREE_IN_EV = 27.211386245988 |
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 |
A potential that gets forces and energy from an NWChem server via a socket.
Implements the i-PI socket protocol to communicate with an NWChem executable that has been launched in server mode (e.g., using task scf optimize and the driver socket directive). This class manages a persistent connection to NWChem. Supports both TCP/IP and UNIX domain sockets.
Definition at line 27 of file SocketNWChemPot.h.
|
explicit |
Definition at line 24 of file SocketNWChemPot.cpp.
|
override |
Definition at line 58 of file SocketNWChemPot.cpp.
|
private |
Definition at line 343 of file SocketNWChemPot.cpp.
|
inlinenodiscardoverridevirtual |
Cauchy stress in eV/Angstrom^3.
sigma = (1/V) dE/dε for the right strain h <- h (I+ε) at fixed fractional coordinates.
Reimplemented from eonc::Potential.
Definition at line 77 of file SocketNWChemPot.h.
|
inlinenodiscardoverridevirtualnoexcept |
True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance.
Reimplemented from eonc::Potential.
Definition at line 73 of file SocketNWChemPot.h.
|
private |
Definition at line 352 of file SocketNWChemPot.cpp.
|
overridevirtual |
The method called to compute forces and energy.
This method implements the full i-PI handshake for a single geometry:
| N | The number of atoms. |
| R | Pointer to the beginning of the position array [x1, y1, z1, ...]. |
| atomicNrs | Pointer to the array of atomic numbers. |
| F | Pointer to the beginning of the force array to be populated. |
| U | Pointer to the potential energy value to be set. |
| variance | Not used by this potential. |
| box | Pointer to the 3x3 simulation box matrix. |
Implements eonc::Potential.
Definition at line 115 of file SocketNWChemPot.cpp.
|
private |
Definition at line 127 of file SocketNWChemPot.cpp.
|
inlinenodiscardoverridevirtualnoexcept |
Whether this potential's force() can be called from multiple threads on the SAME instance.
Python-based potentials return false. Potentials with internal mutex (MetatomicPotential) return true but serialize internally – use needsPerImageInstance() to check if separate instances would enable true parallelism.
Reimplemented from eonc::Potential.
Definition at line 66 of file SocketNWChemPot.h.
|
inlinenodiscardoverridevirtualnoexcept |
One listening socket and one NWChem client.
A second instance would bind the same path, so per-image copies are not independent.
Reimplemented from eonc::Potential.
Definition at line 69 of file SocketNWChemPot.h.
|
private |
Definition at line 390 of file SocketNWChemPot.cpp.
|
private |
Definition at line 367 of file SocketNWChemPot.cpp.
|
inlinenodiscardoverridevirtualnoexcept |
NWChem socket SCF does not support PBC (#188).
Reimplemented from eonc::Potential.
Definition at line 63 of file SocketNWChemPot.h.
|
private |
Definition at line 377 of file SocketNWChemPot.cpp.
|
private |
Definition at line 360 of file SocketNWChemPot.cpp.
|
private |
Definition at line 284 of file SocketNWChemPot.cpp.
| void SocketNWChemPot::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.
| filename | The path to the output file (e.g., "nwchem_socket.nwi"). |
| N | The number of atoms. |
| atom_symbols | A vector of atom symbols (e.g., {"O", "H", "H"}). |
Definition at line 80 of file SocketNWChemPot.cpp.
|
staticconstexprprivate |
Definition at line 112 of file SocketNWChemPot.h.
|
private |
Definition at line 106 of file SocketNWChemPot.h.
|
staticconstexprprivate |
Definition at line 113 of file SocketNWChemPot.h.
|
private |
Definition at line 116 of file SocketNWChemPot.h.
|
private |
Definition at line 107 of file SocketNWChemPot.h.
|
private |
Definition at line 105 of file SocketNWChemPot.h.
|
private |
Definition at line 102 of file SocketNWChemPot.h.
|
private |
Definition at line 100 of file SocketNWChemPot.h.
|
staticconstexprprivate |
Definition at line 110 of file SocketNWChemPot.h.
|
private |
Definition at line 99 of file SocketNWChemPot.h.
|
private |
Definition at line 100 of file SocketNWChemPot.h.
|
private |
Definition at line 95 of file SocketNWChemPot.h.
|
private |
Definition at line 115 of file SocketNWChemPot.h.
|
private |
Definition at line 97 of file SocketNWChemPot.h.
|
private |
Definition at line 93 of file SocketNWChemPot.h.