Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvarproxy_lammps.h
1// -*- c++ -*-
2
3// This file is part of the Collective Variables module (Colvars).
4// The original version of Colvars and its updates are located at:
5// https://github.com/Colvars/colvars
6// Please update all Colvars source files before making any changes.
7// If you wish to distribute your changes, please submit them to the
8// Colvars repository at GitHub.
9
10#ifndef COLVARPROXY_LAMMPS_H
11#define COLVARPROXY_LAMMPS_H
12
13#include "colvarproxy_lammps_version.h" // IWYU pragma: export
14
15#include "colvarmodule.h"
16#include "colvarproxy.h"
17#include "colvartypes.h"
18
19#include "domain.h" // IWYU pragma: keep
20#include "force.h" // IWYU pragma: keep
21#include "lammps.h" // IWYU pragma: keep
22#include "random_park.h"
23#include "update.h" // IWYU pragma: keep
24
28
29 // LAMMPS specific data objects and flags
30 protected:
31 // pointers to LAMMPS class instances
32 LAMMPS_NS::LAMMPS *_lmp;
33 LAMMPS_NS::RanPark *_random;
34
35 // state of LAMMPS properties
36 double bias_energy;
37 cvm::step_number previous_step;
38
39 bool first_timestep;
40 bool do_exit;
41
42 std::vector<int> atoms_types;
43
44 MPI_Comm inter_comm; // MPI comm with 1 root proc from each world
45 int inter_me, inter_num; // rank for the inter replica comm
46
47 public:
48 friend class cvm::atom;
49
50 colvarproxy_lammps(LAMMPS_NS::LAMMPS *lmp);
51
52 ~colvarproxy_lammps() override;
53
54 void init();
55
57 void set_random_seed(int seed);
58
60 void set_replicas_communicator(MPI_Comm root2root);
61
62 int setup() override;
63
64 // disable default and copy constructor
65 private:
68
69 // methods for lammps to move data or trigger actions in the proxy
70 public:
71
72 bool total_forces_enabled() const override { return total_force_requested; };
73 bool total_forces_same_step() const override { return true; };
74 bool want_exit() const { return do_exit; };
75
76 // perform colvars computation. returns biasing energy
77 double compute();
78
79 // Request to set the units used internally by Colvars
80 int set_unit_system(std::string const &units_in, bool check_only) override;
81
83 char const *script_obj_to_str(unsigned char *obj);
84
86 std::vector<std::string> script_obj_to_str_vector(unsigned char *obj);
87
88 void add_energy(cvm::real energy) override { bias_energy += energy; };
89 void request_total_force(bool yesno) override { total_force_requested = yesno; };
90
91 void log(std::string const &message) override;
92 void error(std::string const &message) override;
93
94 cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const override;
95
96 cvm::real rand_gaussian(void) override { return _random->gaussian(); };
97
98 int init_atom(int atom_number) override;
99 int check_atom_id(int atom_number) override;
100
101 inline std::vector<int> *modify_atom_types() { return &atoms_types; }
102
103 int replica_enabled() override;
104 int replica_index() override;
105 int num_replicas() override;
106
107 void replica_comm_barrier() override;
108 int replica_comm_recv(char *msg_data, int buf_len, int src_rep) override;
109 int replica_comm_send(char *msg_data, int msg_len, int dest_rep) override;
110};
111
112#endif
Stores numeric id, mass and all mutable data for an atom, mostly used by a colvar::cvc.
Definition: colvaratoms.h:31
vector of real numbers with three components
Definition: colvartypes.h:727
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:92
Communication between colvars and LAMMPS (implementation of colvarproxy)
Definition: colvarproxy_lammps.h:27
void request_total_force(bool yesno) override
Tell the proxy whether total forces are needed (they may not always be available)
Definition: colvarproxy_lammps.h:89
cvm::real rand_gaussian(void) override
Pseudo-random number with Gaussian distribution.
Definition: colvarproxy_lammps.h:96
int init_atom(int atom_number) override
Definition: colvarproxy_lammps.cpp:335
void replica_comm_barrier() override
Synchronize replica with others.
Definition: colvarproxy_lammps.cpp:283
int replica_index() override
Index of this replica.
Definition: colvarproxy_lammps.cpp:271
int setup() override
(Re)initialize required member data (called after the module)
Definition: colvarproxy_lammps.cpp:106
cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const override
Get the PBC-aware distance vector between two positions.
Definition: colvarproxy_lammps.cpp:201
void set_replicas_communicator(MPI_Comm root2root)
Set the multiple replicas communicator.
Definition: colvarproxy_lammps.cpp:94
void set_random_seed(int seed)
Set the internal seed used by rand_gaussian().
Definition: colvarproxy_lammps.cpp:85
bool total_forces_enabled() const override
Are total forces being used?
Definition: colvarproxy_lammps.h:72
std::vector< std::string > script_obj_to_str_vector(unsigned char *obj)
Convert a command-line argument to a vector of strings.
Definition: colvarproxy_lammps.cpp:241
int set_unit_system(std::string const &units_in, bool check_only) override
Request to set the units used internally by Colvars.
Definition: colvarproxy_lammps.cpp:252
int replica_comm_send(char *msg_data, int msg_len, int dest_rep) override
Send data to other replica.
Definition: colvarproxy_lammps.cpp:303
int num_replicas() override
Total number of replicas.
Definition: colvarproxy_lammps.cpp:277
void add_energy(cvm::real energy) override
Pass restraint energy value for current timestep to MD engine.
Definition: colvarproxy_lammps.h:88
int replica_comm_recv(char *msg_data, int buf_len, int src_rep) override
Receive data from other replica.
Definition: colvarproxy_lammps.cpp:289
void error(std::string const &message) override
Print a message to the main log and/or let the host code know about it.
Definition: colvarproxy_lammps.cpp:226
int check_atom_id(int atom_number) override
Definition: colvarproxy_lammps.cpp:316
int replica_enabled() override
Indicate if multi-replica support is available and active.
Definition: colvarproxy_lammps.cpp:265
bool total_forces_same_step() const override
Are total forces from the current step available?
Definition: colvarproxy_lammps.h:73
char const * script_obj_to_str(unsigned char *obj)
Convert a command-line argument to string.
Definition: colvarproxy_lammps.cpp:234
void log(std::string const &message) override
Print a message to the main log.
Definition: colvarproxy_lammps.cpp:213
bool total_force_requested
Whether the total forces have been requested.
Definition: colvarproxy_system.h:162
Definition: colvarproxy.h:573
Collective variables main module.
Colvars proxy classes.