Skip to content

Commit c2918f4

Browse files
authored
Merge pull request #59 from Zhaoli2042/main
PR: update readme (citation) and movie print bug fix
2 parents 1e001f4 + 6ad9c5c commit c2918f4

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ A detailed installation note for gRASPA on CentOS/Ubuntu 24.04 is documented in
3636
* also available in [Chinese](https://zhaoli2042.github.io/gRASPA-mkdoc/Chinese)
3737
* a doxygen documentation is also available @ https://zhaoli2042.github.io/gRASPA
3838
## Reference
39-
* gRASPA paper is now [online](https://pubs.acs.org/doi/10.1021/acs.jctc.4c01058). Please kindly cite it if you find it useful.
39+
* gRASPA paper is now published. Please kindly cite it if you find it useful.
40+
* Li, Shi, Dubbeldam, Dewing, Knight, Vázquez-Mayagoitia, Snurr,
41+
"Efficient Implementation of Monte Carlo Algorithms on Graphical Processing Units for Simulation of Adsorption in Porous Materials", _J. Chem. Theory Comput_. 2024, 20, 23, 10649–10666
42+
* DOI: [10.1021/acs.jctc.4c01058](https://pubs.acs.org/doi/10.1021/acs.jctc.4c01058)
4043
* Also, please give our repository a :star: if our code helps!
4144
## Table of Code Capabilities
4245
| Functionalities | gRASPA | gRASPA-fast | gRASPA-HTC |

src_clean/axpy.cu

+10-8
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ inline void Copy_AtomData_from_Device(Atoms* System, Atoms* d_a, Components& Sys
5050
HostBox.Cubic = Sims.Box.Cubic;
5151
}
5252

53-
inline void GenerateRestartMovies(Components& SystemComponents, Simulations& Sims, PseudoAtomDefinitions& PseudoAtom, size_t systemIdx, int SimulationMode)
53+
inline void GenerateRestartMovies(Variables& Vars, size_t systemId, PseudoAtomDefinitions& PseudoAtom, int SimulationMode)
5454
{
55+
Components& SystemComponents = Vars.SystemComponents[systemId];
56+
Simulations& Sims = Vars.Sims[systemId];
57+
Boxsize& HostBox = Vars.Box[systemId];
5558
//Generate Restart file during the simulation, regardless of the phase
5659
Atoms device_System[SystemComponents.NComponents.x];
57-
Boxsize HostBox;
5860
Copy_AtomData_from_Device(device_System, Sims.d_a, SystemComponents, HostBox, Sims);
59-
create_Restart_file(0, SystemComponents.HostSystem, SystemComponents, SystemComponents.FF, HostBox, PseudoAtom.Name, systemIdx);
60-
Write_All_Adsorbate_data(0, SystemComponents.HostSystem, SystemComponents, SystemComponents.FF, HostBox, PseudoAtom.Name, systemIdx);
61+
create_Restart_file(0, SystemComponents.HostSystem, SystemComponents, SystemComponents.FF, HostBox, PseudoAtom.Name, systemId);
62+
Write_All_Adsorbate_data(0, SystemComponents.HostSystem, SystemComponents, SystemComponents.FF, HostBox, PseudoAtom.Name, systemId);
6163
//Only generate LAMMPS data movie for production phase
62-
if(SimulationMode == PRODUCTION) create_movie_file(SystemComponents.HostSystem, SystemComponents, HostBox, PseudoAtom.Name, systemIdx);
64+
if(SimulationMode == PRODUCTION) create_movie_file(SystemComponents.HostSystem, SystemComponents, HostBox, PseudoAtom.Name, systemId);
6365
}
6466

6567
///////////////////////////////////////////////////////////
@@ -491,7 +493,7 @@ void Run_Simulation_MultipleBoxes(Variables& Vars, int SimulationMode)
491493
}
492494
}
493495
if(i % SystemComponents[sim].MoviesEvery == 0)//Generate restart file and movies
494-
GenerateRestartMovies(SystemComponents[sim], Sims[sim], SystemComponents[sim].PseudoAtoms, sim, SimulationMode);
496+
GenerateRestartMovies(Vars, sim, SystemComponents[sim].PseudoAtoms, SimulationMode);
495497
}
496498
}
497499
if(i > 0 && i % 500 == 0)
@@ -699,7 +701,7 @@ double Run_Simulation_ForOneBox(Variables& Vars, size_t box_index)
699701
SystemComponents.Tmmc[comp].AdjustTMBias();
700702
}
701703
if(i % SystemComponents.MoviesEvery == 0)//Generate restart file and movies
702-
GenerateRestartMovies(SystemComponents, Sims, SystemComponents.PseudoAtoms, 0, SimulationMode);
704+
GenerateRestartMovies(Vars, box_index, SystemComponents.PseudoAtoms, SimulationMode);
703705
}
704706
//print statistics
705707
if(Cycles > 0)
@@ -713,7 +715,7 @@ double Run_Simulation_ForOneBox(Variables& Vars, size_t box_index)
713715
}
714716
}
715717
//At the end of the sim, print a last-step restart and last-step movie
716-
GenerateRestartMovies(SystemComponents, Sims, SystemComponents.PseudoAtoms, 0, SimulationMode);
718+
GenerateRestartMovies(Vars, box_index, SystemComponents.PseudoAtoms, SimulationMode);
717719
PrintSystemMoves(Vars);
718720

719721
fprintf(SystemComponents.OUTPUT, "===============================\n");

src_clean/mc_widom.h

+15-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ inline void Host_sum_Widom_HGGG_SEPARATE(size_t NumberWidomTrials, double Beta,
4343
//else printf("THERE IS OVERLAP FOR TRIAL %zu, flag = %s\n", i, flag[i] ? "true" : "false");
4444
}
4545
T host_array[HGGG_Nblock * 2];
46+
47+
size_t reasonable_trials_size = reasonable_trials.size();
48+
Trialindex.resize(reasonable_trials_size, 0);
49+
energies.resize(reasonable_trials_size);
50+
Rosen.resize(reasonable_trials_size, 0.0);
51+
4652
for(size_t i = 0; i < reasonable_trials.size(); i++)
4753
{
4854
size_t trial = reasonable_trials[i];
@@ -54,22 +60,25 @@ inline void Host_sum_Widom_HGGG_SEPARATE(size_t NumberWidomTrials, double Beta,
5460
//So translation/rotation summation of energy are not checking the overlaps, so this is the reason for the discrepancy//
5561
for(size_t ijk=0; ijk < HG_Nblock; ijk++) HG_vdw+=host_array[ijk];
5662
for(size_t ijk=HG_Nblock; ijk < HGGG_Nblock; ijk++) GG_vdw+=host_array[ijk];
57-
63+
5864
for(size_t ijk=HGGG_Nblock; ijk < HG_Nblock + HGGG_Nblock; ijk++) HG_real+=host_array[ijk];
5965
for(size_t ijk=HG_Nblock + HGGG_Nblock; ijk < HGGG_Nblock + HGGG_Nblock; ijk++) GG_real+=host_array[ijk];
6066

6167
double tot = static_cast<double>(HG_vdw + GG_vdw);
6268
if(VDWRealBiasing) tot += static_cast<double>(HG_real + GG_real);
63-
69+
6470
MoveEnergy E;
65-
E.HGVDW = static_cast<double>(HG_vdw);
71+
E.HGVDW = static_cast<double>(HG_vdw);
6672
E.HGReal= static_cast<double>(HG_real);
6773
E.GGVDW = static_cast<double>(GG_vdw);
6874
E.GGReal= static_cast<double>(GG_real);
6975
//printf("trial: %zu, HG: %.5f, GG: %.5f, tot: %.5f\n", i, HG_vdw + HG_real, GG_vdw + GG_real, tot);
70-
energies.push_back(E);
71-
Trialindex.push_back(trial);
72-
Rosen.push_back(-Beta*tot);
76+
Trialindex[i] = trial;
77+
energies[i] = E;
78+
Rosen[i] = -Beta*tot;
79+
//energies.push_back(E);
80+
//Trialindex.push_back(trial);
81+
//Rosen.push_back(-Beta*tot);
7382
//printf("Trial %zu ", trial); E.print();
7483
}
7584
}

src_clean/write_data.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <iomanip>
77

88

9-
static inline void WriteBox_LAMMPS(Atoms* System, Components SystemComponents, ForceField FF, Boxsize Box, std::ofstream& textrestartFile, std::vector<std::string> AtomNames)
9+
static inline void WriteBox_LAMMPS(Atoms* System, Components& SystemComponents, ForceField& FF, Boxsize& Box, std::ofstream& textrestartFile, std::vector<std::string>& AtomNames)
1010
{
1111
size_t NumberOfAtoms = 0;
1212
for(size_t i = 0; i < SystemComponents.NComponents.x; i++)
@@ -44,7 +44,7 @@ static inline void WriteBox_LAMMPS(Atoms* System, Components SystemComponents, F
4444
}
4545
}
4646

47-
static inline void WriteAtoms_LAMMPS(Atoms* System, Components SystemComponents, Boxsize Box, std::ofstream& textrestartFile, std::vector<std::string> AtomNames)
47+
static inline void WriteAtoms_LAMMPS(Atoms* System, Components& SystemComponents, Boxsize& Box, std::ofstream& textrestartFile, std::vector<std::string>& AtomNames)
4848
{
4949
textrestartFile << '\n' << "Atoms" << '\n' << '\n';
5050
size_t Atomcount=0; size_t Molcount=0;
@@ -83,7 +83,7 @@ static inline void WriteAtoms_LAMMPS(Atoms* System, Components SystemComponents,
8383
}
8484
}
8585

86-
static inline void WriteAtoms_Restart(Atoms* System, Components SystemComponents, std::ofstream& textrestartFile, std::vector<std::string> AtomNames)
86+
static inline void WriteAtoms_Restart(Atoms* System, Components& SystemComponents, std::ofstream& textrestartFile, std::vector<std::string>& AtomNames)
8787
{
8888
textrestartFile << "Reactions: 0" << "\n";
8989
//size_t Atomcount=0;
@@ -116,7 +116,7 @@ static inline void WriteAtoms_Restart(Atoms* System, Components SystemComponents
116116
}
117117
}
118118

119-
static inline void WriteComponent_Restart(Atoms* System, Components SystemComponents, std::ofstream& textrestartFile, Boxsize& Box)
119+
static inline void WriteComponent_Restart(Atoms* System, Components& SystemComponents, std::ofstream& textrestartFile, Boxsize& Box)
120120
{
121121
textrestartFile << "Components: " << SystemComponents.NComponents.x - SystemComponents.NumberOfFrameworks << " (Adsorbates " << SystemComponents.TotalNumberOfMolecules-SystemComponents.NumberOfFrameworks << ", Cations 0)" << "\n";
122122
textrestartFile << "========================================================================\n";
@@ -145,7 +145,7 @@ static inline void WriteComponent_Restart(Atoms* System, Components SystemCompon
145145
}
146146
}
147147

148-
static inline void WriteCellInfo_Restart(Atoms* System, Components SystemComponents, std::ofstream& textrestartFile, Boxsize& Box)
148+
static inline void WriteCellInfo_Restart(Atoms* System, Components& SystemComponents, std::ofstream& textrestartFile, Boxsize& Box)
149149
{
150150
//size_t Atomcount=0;
151151
textrestartFile << "Cell info:\n";
@@ -219,7 +219,7 @@ static inline void copyFile(const std::string& sourcePath, const std::string& de
219219
//return true;
220220
}
221221

222-
static inline void create_Restart_file(size_t Cycle, Atoms* System, Components SystemComponents, ForceField FF, Boxsize Box, std::vector<std::string> AtomNames, size_t SystemIndex)
222+
static inline void create_Restart_file(size_t Cycle, Atoms* System, Components& SystemComponents, ForceField& FF, Boxsize& Box, std::vector<std::string>& AtomNames, size_t SystemIndex)
223223
{
224224
std::ofstream textrestartFile{};
225225
std::string dirname="Restart/System_" + std::to_string(SystemIndex) + "/";
@@ -239,7 +239,7 @@ static inline void create_Restart_file(size_t Cycle, Atoms* System, Components S
239239
textrestartFile.close();
240240
}
241241

242-
static inline void WriteAllData(Atoms* System, Components SystemComponents, std::ofstream& textrestartFile, std::vector<std::string> AtomNames, size_t i)
242+
static inline void WriteAllData(Atoms* System, Components& SystemComponents, std::ofstream& textrestartFile, std::vector<std::string>& AtomNames, size_t i)
243243
{
244244
//size_t Atomcount=0;
245245
Atoms Data = System[i];
@@ -251,7 +251,7 @@ static inline void WriteAllData(Atoms* System, Components SystemComponents, std:
251251
textrestartFile << " " << Data.MolID[j] << " " << j - Data.MolID[j]*molsize << " " << Data.pos[j].x << " " << Data.pos[j].y << " " << Data.pos[j].z << " " << Data.charge[j] << " " << Data.scale[j] << " " << Data.scaleCoul[j] << " " << Data.Type[j] << '\n';
252252
}
253253

254-
static inline void Write_All_Adsorbate_data(size_t Cycle, Atoms* System, Components SystemComponents, ForceField FF, Boxsize Box, std::vector<std::string> AtomNames, size_t SystemIndex)
254+
static inline void Write_All_Adsorbate_data(size_t Cycle, Atoms* System, Components& SystemComponents, ForceField& FF, Boxsize& Box, std::vector<std::string>& AtomNames, size_t SystemIndex)
255255
{
256256
//std::ofstream textrestartFile{};
257257
std::filesystem::path cwd = std::filesystem::current_path();
@@ -272,7 +272,7 @@ static inline void Write_All_Adsorbate_data(size_t Cycle, Atoms* System, Compone
272272

273273
//Zhao's note on 112623, moved the following to fxn_main.h//
274274
/*
275-
static inline void Write_Lambda(size_t Cycle, Components SystemComponents, size_t SystemIndex)
275+
static inline void Write_Lambda(size_t Cycle, Components& SystemComponents, size_t SystemIndex)
276276
{
277277
std::ofstream textrestartFile{};
278278
std::filesystem::path cwd = std::filesystem::current_path();
@@ -308,7 +308,7 @@ static inline void Write_Lambda(size_t Cycle, Components SystemComponents, size_
308308
textrestartFile.close();
309309
}
310310
311-
static inline void Write_TMMC(size_t Cycle, Components SystemComponents, size_t SystemIndex)
311+
static inline void Write_TMMC(size_t Cycle, Components& SystemComponents, size_t SystemIndex)
312312
{
313313
std::ofstream textTMMCFile{};
314314
std::filesystem::path cwd = std::filesystem::current_path();

0 commit comments

Comments
 (0)