@@ -14,11 +14,10 @@ GNU Lesser General Public License for more details.
1414You should have received a copy of the GNU Lesser General Public License
1515along with plumed. If not, see <http://www.gnu.org/licenses/>.
1616+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
17- #include " PINES.h"
18-
1917#include < string>
2018#include < cmath>
2119#include < iostream>
20+ #include < fstream>
2221#include < cstdio>
2322#include < unordered_map>
2423#include < set>
@@ -29,10 +28,109 @@ along with plumed. If not, see <http://www.gnu.org/licenses/>.
2928#include < functional>
3029#include < vector>
3130
31+ #include " core/ActionWithVirtualAtom.h"
32+ #include " core/ActionWithValue.h"
33+ #include " core/PlumedMain.h"
34+ #include " tools/Stopwatch.h"
35+ #include " tools/PDB.h"
36+ #include " tools/Vector.h"
37+ #include " tools/AtomNumber.h"
38+ #include " tools/SwitchingFunction.h"
39+ #include " tools/Communicator.h"
40+ #include " tools/Units.h"
41+
42+ #include " colvar/Colvar.h"
43+ #include " core/ActionRegister.h"
44+
45+
3246using namespace std ;
3347
3448namespace PLMD {
3549namespace pines {
50+
51+ struct AtomNumberLess {
52+ bool operator ()(const AtomNumber& a, const AtomNumber& b) const {
53+ return a.index () < b.index ();
54+ }
55+ };
56+
57+ class PINES : public PLMD ::colvar::Colvar {
58+ private:
59+ PLMD::Stopwatch timer;
60+ int N_Blocks;
61+ int total_PIV_length;
62+ int inited_step;
63+ int last_step_latched;
64+ bool driver_mode;
65+ bool freeze_selection;
66+ std::vector<int > steps_since_update;
67+ std::vector<int > nstride;
68+ std::string ref_file;
69+ std::vector<SwitchingFunction> sfs;
70+ std::vector<std::string> sw;
71+ std::vector<double > r00;
72+ std::vector<std:: vector<double > > PIV;
73+ std::vector<std:: vector<Vector> > ann_deriv;
74+
75+ std::vector<std:: vector<AtomNumber> > listall;
76+ std::vector<std:: vector<AtomNumber> > listreduced;
77+ std::set<AtomNumber, AtomNumberLess> listreducedall;
78+ std::vector<AtomNumber> listreducedall_vec;
79+ std::unordered_map<int ,int > atom_ind_hashmap;
80+
81+ std::vector<bool > stale_tolerance;
82+ PDB mypdb;
83+ std::vector<std::string> block_params;
84+ std::vector<std::vector<std::vector<AtomNumber> > > block_groups_atom_list;
85+ std::vector<int > block_lengths;
86+ std::vector<int > Buffer_Pairs;
87+ std::vector<int > tot_num_pairs;
88+ std::vector<std::vector<std::vector<bool > > > input_filters;
89+ std::vector<double > delta_pd;
90+ std::vector<double > r_tolerance;
91+ std::vector<std::vector<Vector> > PL_atoms_ref_coords;
92+ std::vector<std::vector<std::pair<AtomNumber,AtomNumber> > > Exclude_Pairs;
93+ std::vector<std::vector<std::vector<std::string> > > Name_list;
94+ std::vector<std::vector<std::vector<AtomNumber> > > ID_list;
95+ std::vector<std::vector<std::vector<int > > > ResID_list;
96+ std::vector<char > all_g1g2_pairs;
97+ std::vector<std::vector<std::pair<double , std::pair<AtomNumber,AtomNumber> > > > vecMaxHeapVecs;
98+ std::vector<std::vector<std::pair<AtomNumber,AtomNumber> > > latched_pairs;
99+ std::vector<char > preupdated_block;
100+ std::vector<bool > isFirstBuild;
101+
102+ bool atomMatchesFilters (int n, int g, AtomNumber ind, int resid, const std::string& atom_name);
103+ void buildMaxHeapVecBlock (int n, const PDB& mypdb, std::vector<std::pair<double , std::pair<AtomNumber, AtomNumber>>>& heap);
104+ void updateBlockPairList (int n, std::vector<std::pair<double , std::pair<AtomNumber, AtomNumber>>>& heap);
105+ double calculateDistance (int n, const AtomNumber& ind0, const AtomNumber& ind1, const PDB& mypdb);
106+ std::ofstream log;
107+ bool ensureBlockUpdated (int n);
108+ void latchFromCurrentHeaps ();
109+ void logMsg (const std::string& msg, const std::string& section);
110+ void logMsg (const Vector& vec, const std::string& section);
111+ void resizeAllContainers (int N);
112+
113+ public:
114+ static void registerKeywords ( Keywords& keys );
115+ explicit PINES (const ActionOptions&);
116+ // ~PINES();
117+ // active methods:
118+ struct MinCompareDist {
119+ bool operator ()(const std::pair<double , std::pair<AtomNumber, AtomNumber>>& p1, const std::pair<double , std::pair<AtomNumber, AtomNumber>>& p2) {
120+ return p1.first < p2.first ; // Min heap
121+ }
122+ };
123+ struct MaxCompareDist {
124+ bool operator ()(const std::pair<double , std::pair<AtomNumber, AtomNumber>>& p1, const std::pair<double , std::pair<AtomNumber, AtomNumber>>& p2) {
125+ return p1.first > p2.first ; // Max heap
126+ }
127+ };
128+
129+ virtual void calculate ();
130+ void checkFieldsAllowed () {}
131+ // -- SD prepare to requestAtoms during simulation
132+ void prepare () override ;
133+ };
36134// +PLUMEDOC PINES
37135// Documentation to be added.
38136// +ENDPLUMEDOC PINES
@@ -234,8 +332,8 @@ double PINES::calculateDistance(int n, const AtomNumber& ind0, const AtomNumber&
234332
235333void PINES::resizeAllContainers (int N) {
236334 // Outer containers
237- nstride.resize (N,1 );
238- steps_since_update.resize (N, 0 );
335+ nstride.assign (N,1 );
336+ steps_since_update.assign (N, 0 );
239337 block_params.resize (N);
240338 block_groups_atom_list.resize (N);
241339 block_lengths.resize (N);
@@ -251,16 +349,16 @@ void PINES::resizeAllContainers(int N) {
251349 r00.resize (N);
252350 sw.resize (N);
253351 sfs.resize (N);
254- delta_pd.resize (N, 0.0 );
255- r_tolerance.resize (N, 0.0 );
352+ delta_pd.assign (N, 0.0 );
353+ r_tolerance.assign (N, 0.0 );
256354 PL_atoms_ref_coords.resize (N);
257355 input_filters.resize (N);
258356 ID_list.resize (N);
259357 ResID_list.resize (N);
260358 Name_list.resize (N);
261359 atom_ind_hashmap.clear ();
262360 latched_pairs.resize (N);
263- isFirstBuild.resize (N,true );
361+ isFirstBuild.assign (N,true );
264362
265363 // Per-block inner structures
266364 for (int n = 0 ; n < N; n++) {
@@ -275,7 +373,7 @@ void PINES::resizeAllContainers(int N) {
275373 // Final 3D input_filters init
276374 for (int n = 0 ; n < N; n++) {
277375 for (int g = 0 ; g < 2 ; g++) {
278- input_filters[n][g].resize (3 , false ); // [ID, ResID, Name]
376+ input_filters[n][g].assign (3 , false ); // [ID, ResID, Name]
279377 }
280378 }
281379}
0 commit comments