Skip to content

Commit

Permalink
updates: read/write restart/LMP data files
Browse files Browse the repository at this point in the history
1. restart files (RASPA style): 
* The previous restart file (RASPA style) will be copied as a backup and then the new restart file will be written
2. Read LAMMPS data file:
* LAMMPS data file can now be used as an alternative way to read an initial configuration (alternative to RASPA-2 style restart file)
  * The user will have the option to determine: 
    1) what component to start with (can skip/read the zeroth component which is the framework). 
    2) whether to read the box size information from the LAMMPS data file
  * The user need to have component information for each atom in their lammps data file (LMPDataInitial/System_0/init.data, put it in the same folder as your input files)
    * Example: 
    896 1 2 -0.925934 14.2725 14.5959 17.791 # mof.cif O
    897 2 6 0 4.51168 9.47626 11.357 # TIP4P Ow 
3. Write LAMMPS data file:
* To be compatible with the last bullet point from the previous feature (read lammps data file), now gRASPA will output the component and pseudo-atom information when writing LAMMPS data file
  • Loading branch information
Zhaoli2042 authored May 27, 2024
1 parent e7f16db commit 8a65f3e
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 39 deletions.
45 changes: 29 additions & 16 deletions src_clean/data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ enum ROTATION_AXIS {X = 0, Y, Z, SELF_DEFINED};

enum INTERACTION_TYPES {HH = 0, HG, GG};

enum RESTART_FILE_TYPES {RASPA_RESTART = 0, LAMMPS_DATA};

//Zhao's note: For the stage of evaluating total energy of the system//
enum ENERGYEVALSTAGE {INITIAL = 0, CREATEMOL, FINAL, CREATEMOL_DELTA, DELTA, CREATEMOL_DELTA_CHECK, DELTA_CHECK, DRIFT, AVERAGE, AVERAGE_ERR};

Expand Down Expand Up @@ -910,27 +912,29 @@ struct Components
MoveEnergy tempdeltaE;
MoveEnergy CreateMoldeltaE;
MoveEnergy deltaE;
double FrameworkEwald={0.0};
bool HasTailCorrection = {false}; // An overall flag for tail correction
bool ReadRestart = {false}; // Whether to use restart files (RestartInitial)
bool SingleSwap={false};
double FrameworkEwald=0.0;
bool HasTailCorrection = false; // An overall flag for tail correction
bool ReadRestart = false; // Whether to use restart files //Zhao's note: this can be either RASPA-2-type Restart file or LAMMPS data file //
int RestartInputFileType = RASPA_RESTART; // can choose from: RASPA_RESTART or LAMMPS_DATA (see enum at the beginning of this file)
bool Read_BoxsizeRestart = false; // Whether to read boxsize from initial configuration file //
bool SingleSwap=false;
///////////////////////////
// DNN Related Variables //
///////////////////////////
//General DNN Flags//
bool UseDNNforHostGuest = {false};
size_t TranslationRotationDNNReject={0};
size_t ReinsertionDNNReject={0};
size_t InsertionDNNReject={0};
size_t DeletionDNNReject={0};
size_t SingleSwapDNNReject={0};
bool UseDNNforHostGuest = false;
size_t TranslationRotationDNNReject=0;
size_t ReinsertionDNNReject=0;
size_t InsertionDNNReject=0;
size_t DeletionDNNReject=0;
size_t SingleSwapDNNReject=0;
//DNN and Host-Guest Drift//
double SingleMoveDNNDrift={0.0};
double ReinsertionDNNDrift={0.0};
double InsertionDNNDrift={0.0};
double DeletionDNNDrift={0.0};
double SingleSwapDNNDrift={0.0};
double DNNDrift = {100000.0};
double SingleMoveDNNDrift=0.0;
double ReinsertionDNNDrift=0.0;
double InsertionDNNDrift=0.0;
double DeletionDNNDrift=0.0;
double SingleSwapDNNDrift=0.0;
double DNNDrift = 100000.0;
double DNNEnergyConversion;
bool UseAllegro = false;
bool UseLCLin = false;
Expand Down Expand Up @@ -980,6 +984,15 @@ struct Components
std::vector<std::complex<double>> AdsorbateEik; // Stored Ewald Vectors for Adsorbate
std::vector<std::complex<double>> FrameworkEik; // Stored Ewald Vectors for Framework
std::vector<std::complex<double>> tempEik; // Ewald Vector for temporary storage
size_t MatchMoleculeNameToComponentID(std::string Name)
{
for(size_t i = 0; i < MoleculeName.size(); i++)
if(MoleculeName[i] == Name)
{
return i;
}
throw std::runtime_error("CANNOT find Molecule Names match " + Name + " !!!! CHECK YOUR FILE!");
}
void UpdatePseudoAtoms(int MoveType, size_t component)
{
switch(MoveType)
Expand Down
20 changes: 12 additions & 8 deletions src_clean/fxn_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,18 @@ inline void Copy_AtomData_from_Device(Atoms* System, Atoms* Host_System, Atoms*
for(size_t ijk=0; ijk < SystemComponents.Total_Components; ijk++)
{
// if the host allocate_size is different from the device, allocate more space on the host
Host_System[ijk].pos = (double3*) malloc(System[ijk].Allocate_size*sizeof(double3));
Host_System[ijk].scale = (double*) malloc(System[ijk].Allocate_size*sizeof(double));
Host_System[ijk].charge = (double*) malloc(System[ijk].Allocate_size*sizeof(double));
Host_System[ijk].scaleCoul = (double*) malloc(System[ijk].Allocate_size*sizeof(double));
Host_System[ijk].Type = (size_t*) malloc(System[ijk].Allocate_size*sizeof(size_t));
Host_System[ijk].MolID = (size_t*) malloc(System[ijk].Allocate_size*sizeof(size_t));
Host_System[ijk].size = System[ijk].size;
Host_System[ijk].Allocate_size = System[ijk].Allocate_size;
size_t current_allocated_size = System[ijk].Allocate_size;
if(current_allocated_size != Host_System[ijk].Allocate_size) //Need to update host
{
Host_System[ijk].pos = (double3*) malloc(System[ijk].Allocate_size*sizeof(double3));
Host_System[ijk].scale = (double*) malloc(System[ijk].Allocate_size*sizeof(double));
Host_System[ijk].charge = (double*) malloc(System[ijk].Allocate_size*sizeof(double));
Host_System[ijk].scaleCoul = (double*) malloc(System[ijk].Allocate_size*sizeof(double));
Host_System[ijk].Type = (size_t*) malloc(System[ijk].Allocate_size*sizeof(size_t));
Host_System[ijk].MolID = (size_t*) malloc(System[ijk].Allocate_size*sizeof(size_t));
Host_System[ijk].Allocate_size = System[ijk].Allocate_size;
}
Host_System[ijk].size = System[ijk].size; //Zhao's note: no matter what, the size (not allocated size) needs to be updated

cudaMemcpy(Host_System[ijk].pos, System[ijk].pos, sizeof(double3)*System[ijk].Allocate_size, cudaMemcpyDeviceToHost);
cudaMemcpy(Host_System[ijk].scale, System[ijk].scale, sizeof(double)*System[ijk].Allocate_size, cudaMemcpyDeviceToHost);
Expand Down
75 changes: 61 additions & 14 deletions src_clean/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@

#include <unistd.h>
#include <limits.h>

void printMemoryUsage()
{
std::ifstream file("/proc/self/statm");
if (file.is_open())
{
long totalProgramSize, residentSet, sharedPages, text, data, unused, library;
file >> totalProgramSize >> residentSet >> sharedPages >> text >> unused >> data >> library;

// Convert the sizes from pages to bytes
long pageSize = sysconf(_SC_PAGE_SIZE);
totalProgramSize *= pageSize;
residentSet *= pageSize;
sharedPages *= pageSize;
text *= pageSize;
data *= pageSize;

std::cout << "Total Program Size: " << totalProgramSize / (1024 * 1024) << " MB" << std::endl;
std::cout << "Resident Set Size: " << residentSet / (1024 * 1024) << " MB" << std::endl;
std::cout << "Shared Pages: " << sharedPages / (1024 * 1024) << " MB" << std::endl;
std::cout << "Text (code): " << text / (1024 * 1024) << " MB" << std::endl;
std::cout << "Data + Stack: " << data / (1024 * 1024) << " MB" << std::endl;
}
else
{
std::cerr << "Unable to open /proc/self/statm" << std::endl;
}
}

int main(void)
{
//Zhao's note: Before everything starts, see if all the lines in Input file can be found in read_data.cpp//
Expand Down Expand Up @@ -197,36 +226,52 @@ int main(void)

SystemComponents.push_back(TempComponents);
//}
Setup_Box_Temperature_Pressure(Constants, SystemComponents[a], Box[a]);
Sims[a].Box.Pressure = Box[a].Pressure; Sims[a].Box.Volume = Box[a].Volume;
Sims[a].Box.Cubic = Box[a].Cubic; Sims[a].Box.ReciprocalCutOff = Box[a].ReciprocalCutOff;
Sims[a].Box.Alpha = Box[a].Alpha; Sims[a].Box.Prefactor = Box[a].Prefactor;
Sims[a].Box.tol1 = Box[a].tol1; Sims[a].Box.ExcludeHostGuestEwald = Box[a].ExcludeHostGuestEwald;


//Calculate Fugacity Coefficient//
//Note pressure in Box variable is already converted to internal units//
ComputeFugacity(SystemComponents[a], PRESSURE, SystemComponents[a].Temperature);
//throw std::runtime_error("EXIT, just test Fugacity Coefficient\n");


cudaMalloc(&Sims[a].Box.Cell, sizeof(double) * 9); cudaMalloc(&Sims[a].Box.InverseCell, sizeof(double) * 9);
cudaMemcpy(Sims[a].Box.Cell, Box[a].Cell, 9 * sizeof(double), cudaMemcpyHostToDevice);
cudaMemcpy(Sims[a].Box.InverseCell, Box[a].InverseCell, 9 * sizeof(double), cudaMemcpyHostToDevice);
Sims[a].Box.kmax = Box[a].kmax;
// PREPARE VALUES FOR THE WIDOM STRUCT, DECLARE THE RESULT POINTERS IN WIDOM //
WidomArray.push_back(Widom);
Prepare_Widom(WidomArray[a], Box[a], Sims[a], SystemComponents[a], SystemComponents[a].HostSystem);

///////////////////////////////////
// Read Restart file for Systems //
///////////////////////////////////
//Zhao's note: here think about multiple simulations where we are doing indepedent simulations, each has a fractional molecule, need to be careful//
bool AlreadyHasFractionalMolecule = false;
Atoms device_System[NComponents.x];
cudaMalloc(&Sims[a].d_a, sizeof(Atoms)*NComponents.x);
//Read initial configurations either from restart file or from lammps data file//
if(RunSingleSim)
{
if(a == SelectedSim && ReadRestart) {RestartFileParser(Sims[a], Box[a], SystemComponents[a]); AlreadyHasFractionalMolecule = true;}
if(a == SelectedSim && ReadRestart)
{
ReadRestartInputFileType(SystemComponents[a]);
if(SystemComponents[a].RestartInputFileType == RASPA_RESTART)
{
RestartFileParser(Sims[a], Box[a], SystemComponents[a]); AlreadyHasFractionalMolecule = true;
}
else if(SystemComponents[a].RestartInputFileType == LAMMPS_DATA)
{
LMPDataFileParser(Sims[a], Box[a], SystemComponents[a]);
}
}
}
//Zhao's note: move copying cell information to GPU after reading restart
// PREPARE VALUES FOR THE WIDOM STRUCT, DECLARE THE RESULT POINTERS IN WIDOM //
WidomArray.push_back(Widom);
Prepare_Widom(WidomArray[a], Box[a], Sims[a], SystemComponents[a], SystemComponents[a].HostSystem);

Setup_Box_Temperature_Pressure(Constants, SystemComponents[a], Box[a]);
Sims[a].Box.Pressure = Box[a].Pressure; Sims[a].Box.Volume = Box[a].Volume;
Sims[a].Box.Cubic = Box[a].Cubic; Sims[a].Box.ReciprocalCutOff = Box[a].ReciprocalCutOff;
Sims[a].Box.Alpha = Box[a].Alpha; Sims[a].Box.Prefactor = Box[a].Prefactor;
Sims[a].Box.tol1 = Box[a].tol1; Sims[a].Box.ExcludeHostGuestEwald = Box[a].ExcludeHostGuestEwald;

cudaMemcpy(Sims[a].Box.Cell, Box[a].Cell, 9 * sizeof(double), cudaMemcpyHostToDevice);
cudaMemcpy(Sims[a].Box.InverseCell, Box[a].InverseCell, 9 * sizeof(double), cudaMemcpyHostToDevice);
Sims[a].Box.kmax = Box[a].kmax;

Copy_Atom_data_to_device((size_t) NComponents.x, device_System, SystemComponents[a].HostSystem);
Prepare_TempSystem_On_Host(SystemComponents[a].TempSystem);
cudaMemcpy(Sims[a].d_a, device_System, sizeof(Atoms)*NComponents.x, cudaMemcpyHostToDevice);
Expand Down Expand Up @@ -352,6 +397,8 @@ int main(void)
// PRINT MOVIE FILE //
//////////////////////
GenerateSummaryAtEnd(0, SystemComponents, Sims, FF, Box, PseudoAtom);
//Check CPU mem used//
printMemoryUsage();
/*
if(SystemComponents[a].UseDNNforHostGuest)
{
Expand Down
Loading

0 comments on commit 8a65f3e

Please sign in to comment.