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 "colvarmodule.h"
14#include "colvarproxy.h"
15
16// forward declarations
17
18namespace LAMMPS_NS {
19class LAMMPS;
20class RanPark;
21} // namespace LAMMPS_NS
22
26
27 // LAMMPS specific data objects and flags
28 protected:
29 // pointers to LAMMPS class instances
30 LAMMPS_NS::LAMMPS *_lmp;
31 LAMMPS_NS::RanPark *_random;
32
33 // state of LAMMPS properties
34 double bias_energy;
35 cvm::step_number previous_step;
36
37 bool first_timestep;
38 bool do_exit;
39
41 std::vector<int> atoms_types;
42
43 public:
44 colvarproxy_lammps(LAMMPS_NS::LAMMPS *lmp);
45 ~colvarproxy_lammps() override;
46
47 // disable default and copy constructor
48 colvarproxy_lammps() = delete;
49 colvarproxy_lammps(const colvarproxy_lammps &) = delete;
50
51 void init();
52
54 void set_random_seed(int seed);
55
56 int setup() override;
57
58 // methods for lammps to move data or trigger actions in the proxy
59 public:
60 [[nodiscard]] bool total_forces_enabled() const override { return total_force_requested; };
61 // Total forces are saved at end of step, only processed at the next step
62 [[nodiscard]] bool total_forces_same_step() const override { return false; };
63 [[nodiscard]] bool want_exit() const { return do_exit; };
64
65 // perform colvars computation. returns biasing energy
66 double compute();
67
68 // Request to set the units used internally by Colvars
69 int set_unit_system(std::string const &units_in, bool check_only) override;
70
72 char const *script_obj_to_str(unsigned char *obj);
73
75 std::vector<std::string> script_obj_to_str_vector(unsigned char *obj);
76
77 void add_energy(cvm::real energy) override { bias_energy += energy; };
78 void request_total_force(bool yesno) override { total_force_requested = yesno; };
79
80 void log(std::string const &message) override;
81 void error(std::string const &message) override;
82
83 cvm::real rand_gaussian() override;
84
85 int init_atom(int atom_number) override;
86 int init_atom(cvm::residue_id const &residue, std::string const &atom_name,
87 std::string const &segment_id) override
88 {
89 return colvarproxy::init_atom(residue, atom_name, segment_id);
90 }
91
92 int check_atom_id(int atom_number) override;
93 int check_atom_id(cvm::residue_id const &residue, std::string const &atom_name,
94 std::string const &segment_id) override
95 {
96 return colvarproxy::check_atom_id(residue, atom_name, segment_id);
97 }
98
99 inline std::vector<int> *modify_atom_types() { return &atoms_types; }
100};
101
102#endif
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:99
int residue_id
Residue identifier.
Definition: colvarmodule.h:248
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:96
virtual int init_atom(int atom_number)
Definition: colvarproxy.cpp:77
virtual int check_atom_id(int atom_number)
Definition: colvarproxy.cpp:83
Communication between colvars and LAMMPS (implementation of colvarproxy)
Definition: colvarproxy_lammps.h:25
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:78
int init_atom(int atom_number) override
Definition: colvarproxy_lammps.cpp:244
int setup() override
(Re)initialize required member data (called after the module)
Definition: colvarproxy_lammps.cpp:93
std::vector< int > atoms_types
Track the type of each atom to retrieve atom properties during setup.
Definition: colvarproxy_lammps.h:41
void set_random_seed(int seed)
Set the internal seed used by rand_gaussian().
Definition: colvarproxy_lammps.cpp:77
bool total_forces_enabled() const override
Are total forces being used?
Definition: colvarproxy_lammps.h:60
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:201
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:212
void add_energy(cvm::real energy) override
Pass restraint energy value for current timestep to MD engine.
Definition: colvarproxy_lammps.h:77
cvm::real rand_gaussian() override
Pseudo-random number with Gaussian distribution.
Definition: colvarproxy_lammps.cpp:84
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:185
int check_atom_id(int atom_number) override
Definition: colvarproxy_lammps.cpp:225
bool total_forces_same_step() const override
Definition: colvarproxy_lammps.h:62
int check_atom_id(cvm::residue_id const &residue, std::string const &atom_name, std::string const &segment_id) override
Check that this atom is valid, but do not initialize it yet.
Definition: colvarproxy_lammps.h:93
char const * script_obj_to_str(unsigned char *obj)
Convert a command-line argument to string.
Definition: colvarproxy_lammps.cpp:193
void log(std::string const &message) override
Print a message to the main log.
Definition: colvarproxy_lammps.cpp:178
int init_atom(cvm::residue_id const &residue, std::string const &atom_name, std::string const &segment_id) override
Definition: colvarproxy_lammps.h:86
bool total_force_requested
Whether the total forces have been requested.
Definition: colvarproxy_system.h:182
Definition: colvarproxy.h:568
Collective variables main module.
Colvars proxy classes.