107 std::vector<double3> CMatrix;
108 std::vector<double> WLBias;
109 std::vector<double> TMBias;
110 std::vector<double> ln_g;
111 std::vector<double> lnpi;
112 std::vector<double> forward_lnpi;
113 std::vector<double> reverse_lnpi;
114 std::vector<double> Histogram;
115 double WLFactor = 1.0;
116 size_t MaxMacrostate = 0;
117 size_t MinMacrostate = 0;
118 size_t nbinPerMacrostate = 1;
119 size_t currentBin = 0;
121 size_t UpdateTMEvery = 5000;
122 size_t TMUpdateTimes = 0;
124 bool DoUseBias =
false;
125 bool UseWLBias =
false;
126 bool UseTMBias =
true;
127 bool RejectOutofBound =
true;
128 bool TMMCRestart =
false;
129 bool RezeroAfterInitialization =
false;
132 void Update(
double Pacc,
size_t N,
int MoveType)
135 if (Pacc > 1.0) Pacc = 1.0;
136 size_t BinLocation = (N - MinMacrostate) * nbinPerMacrostate + currentBin;
139 case TRANSLATION:
case ROTATION:
case REINSERTION:
141 if(RejectOutofBound && ((N > MaxMacrostate) || (N < MinMacrostate)))
return;
142 CMatrix[BinLocation].y += Pacc;
143 ln_g[BinLocation] += WLFactor;
144 WLBias[BinLocation] = -ln_g[N];
145 Histogram[BinLocation] ++;
148 case INSERTION:
case SINGLE_INSERTION:
150 size_t NewBinLocation = (N - MinMacrostate + 1) * nbinPerMacrostate + currentBin;
151 CMatrix[BinLocation].z += Pacc;
152 CMatrix[BinLocation].y += 1-Pacc;
154 if(RejectOutofBound && ((N + 1) > MaxMacrostate))
159 Histogram[NewBinLocation] ++;
160 ln_g[NewBinLocation] += WLFactor;
161 WLBias[NewBinLocation] = -ln_g[N];
164 case DELETION:
case SINGLE_DELETION:
166 size_t NewBinLocation = (N - MinMacrostate - 1) * nbinPerMacrostate + currentBin;
167 CMatrix[BinLocation].x += Pacc;
168 CMatrix[BinLocation].y += 1-Pacc;
169 ln_g[BinLocation] += WLFactor;
170 int Update_State =
static_cast<int>(BinLocation) - 1;
171 if(RejectOutofBound && (Update_State <
static_cast<int>(MinMacrostate)))
173 Histogram[BinLocation] ++;
176 Histogram[NewBinLocation] ++;
177 ln_g[NewBinLocation] += WLFactor;
178 WLBias[NewBinLocation] = -ln_g[N];
181 case CBCF_LAMBDACHANGE:
case CBCF_INSERTION:
case CBCF_DELETION:
183 printf(
"Use the SPECIAL FUNCTION FOR TMMC + CBCFC\n");
200 void UpdateCBCF(
double Pacc,
size_t N,
int change)
203 if (Pacc > 1.0) Pacc = 1.0;
204 size_t BinLocation = (N - MinMacrostate) * nbinPerMacrostate + currentBin;
205 size_t NewBinLocation = BinLocation + change;
206 size_t NTotalBins = Histogram.size();
207 if(RejectOutofBound && (NewBinLocation >= NTotalBins || ((
int) BinLocation + change) < 0))
return;
209 CMatrix[BinLocation].z += Pacc;
210 CMatrix[BinLocation].y += 1-Pacc;
211 Histogram[NewBinLocation] ++;
212 ln_g[NewBinLocation] += WLFactor;
213 WLBias[NewBinLocation] = -ln_g[N];
219 void ApplyWLBias(
double& preFactor,
size_t N,
int MoveType)
221 if(!DoTMMC || !DoUseBias || !UseWLBias)
return;
222 if(N < MinMacrostate || N > MaxMacrostate)
return;
225 case TRANSLATION:
case ROTATION:
case REINSERTION:
230 case INSERTION:
case SINGLE_INSERTION:
case CBCF_INSERTION:
232 if(RejectOutofBound && (N + 1) > MaxMacrostate)
return;
234 double TMMCBias = WLBias[N + 1] - WLBias[N];
235 TMMCBias = std::exp(TMMCBias);
236 preFactor *= TMMCBias;
239 case DELETION:
case SINGLE_DELETION:
case CBCF_DELETION:
241 if(RejectOutofBound && (N - 1) < MinMacrostate)
return;
243 double TMMCBias = WLBias[N - 1] - WLBias[N];
244 TMMCBias = std::exp(TMMCBias);
245 preFactor *= TMMCBias;
250 void ApplyWLBiasCBCF(
double& preFactor,
size_t N,
int change)
252 if(!DoTMMC || !DoUseBias || !UseWLBias)
return;
253 if(N < MinMacrostate || N > MaxMacrostate)
return;
254 size_t BinLocation = (N - MinMacrostate) * nbinPerMacrostate + currentBin;
255 size_t NewBinLocation = BinLocation + change;
256 size_t NTotalBins = Histogram.size();
257 if(RejectOutofBound && (NewBinLocation >= NTotalBins || ((
int) BinLocation + change) < 0))
return;
258 double TMMCBias = WLBias[NewBinLocation] - WLBias[BinLocation];
259 TMMCBias = std::exp(TMMCBias);
260 preFactor *= TMMCBias;
266 void ApplyTMBias(
double& preFactor,
size_t N,
int MoveType)
268 if(!DoTMMC || !DoUseBias || !UseTMBias)
return;
269 if(N < MinMacrostate || N > MaxMacrostate)
return;
272 case TRANSLATION:
case ROTATION:
case REINSERTION:
case CBCF_LAMBDACHANGE:
277 case INSERTION:
case SINGLE_INSERTION:
case CBCF_INSERTION:
279 if(RejectOutofBound && (N + 1) > MaxMacrostate)
return;
281 double TMMCBias = TMBias[N + 1] - TMBias[N];
282 TMMCBias = std::exp(TMMCBias);
283 preFactor *= TMMCBias;
286 case DELETION:
case SINGLE_DELETION:
case CBCF_DELETION:
288 if(RejectOutofBound && (N - 1) < MinMacrostate)
return;
290 double TMMCBias = TMBias[N - 1] - TMBias[N];
291 TMMCBias = std::exp(TMMCBias);
292 preFactor *= TMMCBias;
297 void ApplyTMBiasCBCF(
double& preFactor,
size_t N,
int change)
299 if(!DoTMMC || !DoUseBias || !UseWLBias)
return;
300 if(N < MinMacrostate || N > MaxMacrostate)
return;
301 size_t BinLocation = (N - MinMacrostate) * nbinPerMacrostate + currentBin;
302 size_t NewBinLocation = BinLocation + change;
303 size_t NTotalBins = Histogram.size();
304 if(RejectOutofBound && (NewBinLocation >= NTotalBins || ((
int) BinLocation + change) < 0))
return;
305 double TMMCBias = TMBias[NewBinLocation] - TMBias[BinLocation];
306 TMMCBias = std::exp(TMMCBias);
307 preFactor *= TMMCBias;
312 if(!DoTMMC || !DoUseBias || !UseTMBias)
return;
316 size_t MinVisited = 0;
size_t MaxVisited = 0;
317 size_t nonzeroCount=0;
319 size_t NTotalBins = Histogram.size();
320 for(
size_t a = 0; a < NTotalBins; a++)
322 if(Histogram[a] != 0)
324 if(nonzeroCount==0) MinVisited = a;
330 lnpi[MinVisited] = 0.0;
331 double Maxlnpi = lnpi[MinVisited];
334 for(
size_t a = MinVisited; a < MaxVisited; a++)
337 if(CMatrix[a].z != 0) lnpi[a+1] = lnpi[a] + std::log(CMatrix[a].z) - std::log(CMatrix[a].x + CMatrix[a].y + CMatrix[a].z);
338 forward_lnpi[a+1] = lnpi[a+1];
339 if(CMatrix[a+1].x != 0) lnpi[a+1] = lnpi[a+1] - std::log(CMatrix[a+1].x) + std::log(CMatrix[a+1].x + CMatrix[a+1].y + CMatrix[a+1].z);
340 reverse_lnpi[a+1] = lnpi[a+1];
342 if(lnpi[a+1] > Maxlnpi) Maxlnpi = lnpi[a+1];
345 for(
size_t a = 0; a < MinVisited; a++) lnpi[a] = lnpi[MinVisited];
346 for(
size_t a = MaxVisited; a < NTotalBins; a++) lnpi[a] = lnpi[MaxVisited];
348 double NormalFactor = 0.0;
349 for(
size_t a = 0; a < NTotalBins; a++) lnpi[a] -= Maxlnpi;
350 for(
size_t a = 0; a < NTotalBins; a++) NormalFactor += std::exp(lnpi[a]);
352 NormalFactor = -std::log(NormalFactor);
354 for(
size_t a = 0; a < NTotalBins; a++)
356 lnpi[a] += NormalFactor;
361 void TreatAccOutofBound(
bool& Accept,
size_t N,
int MoveType)
364 if(!Accept || !RejectOutofBound)
return;
367 case TRANSLATION:
case ROTATION:
case REINSERTION:
372 case INSERTION:
case SINGLE_INSERTION:
374 if(RejectOutofBound && (N + 1) > MaxMacrostate) Accept =
false;
377 case DELETION:
case SINGLE_DELETION:
379 if(RejectOutofBound && (N - 1) < MinMacrostate) Accept =
false;
384 void TreatAccOutofBoundCBCF(
bool& Accept,
size_t N,
int change)
387 if(!Accept || !RejectOutofBound)
return;
388 size_t BinLocation = (N - MinMacrostate) * nbinPerMacrostate + currentBin;
389 size_t NewBinLocation = BinLocation + change;
390 size_t NTotalBins = Histogram.size();
391 if(NewBinLocation >= NTotalBins) Accept =
false;
396 if(!DoTMMC || !RezeroAfterInitialization)
return;
397 double3 temp = {0.0, 0.0, 0.0};
398 std::fill(CMatrix.begin(), CMatrix.end(), temp);
399 std::fill(Histogram.begin(), Histogram.end(), 0.0);
400 std::fill(lnpi.begin(), lnpi.end(), 0.0);
401 std::fill(TMBias.begin(), TMBias.end(), 1.0);
418 double TranslationProb =0.0;
419 double RotationProb =0.0;
420 double SpecialRotationProb =0.0;
421 double WidomProb =0.0;
422 double SwapProb =0.0;
423 double ReinsertionProb =0.0;
424 double IdentitySwapProb =0.0;
425 double CBCFProb =0.0;
426 double TotalProb =0.0;
428 int TranslationAccepted = 0;
429 int TranslationTotal = 0;
430 int CumTranslationAccepted = 0;
431 int CumTranslationTotal = 0;
432 double TranslationAccRatio = 0.0;
434 int RotationAccepted = 0;
435 int RotationTotal = 0;
436 int CumRotationAccepted = 0;
437 int CumRotationTotal = 0;
438 double RotationAccRatio = 0;
440 int SpecialRotationAccepted = 0;
441 int SpecialRotationTotal = 0;
442 double SpecialRotationAccRatio = 0;
444 size_t InsertionTotal = 0;
445 size_t InsertionAccepted = 0;
447 size_t DeletionTotal = 0;
448 size_t DeletionAccepted = 0;
450 size_t ReinsertionTotal = 0;
451 size_t ReinsertionAccepted = 0;
453 size_t CBCFTotal = 0;
454 size_t CBCFAccepted = 0;
455 size_t CBCFInsertionTotal = 0;
456 size_t CBCFInsertionAccepted = 0;
457 size_t CBCFLambdaTotal = 0;
458 size_t CBCFLambdaAccepted = 0;
459 size_t CBCFDeletionTotal = 0;
460 size_t CBCFDeletionAccepted = 0;
462 std::vector<size_t>IdentitySwap_Total_TO;
463 std::vector<size_t>IdentitySwap_Acc_TO;
464 size_t IdentitySwapAddAccepted=0;
465 size_t IdentitySwapAddTotal=0;
466 size_t IdentitySwapRemoveAccepted=0;
467 size_t IdentitySwapRemoveTotal=0;
470 std::vector<double2>MolAverage;
472 std::vector<RosenbluthWeight>Rosen;
473 void NormalizeProbabilities()
476 TotalProb+=TranslationProb;
477 TotalProb+=RotationProb;
478 TotalProb+=SpecialRotationProb;
479 TotalProb+=WidomProb;
480 TotalProb+=ReinsertionProb;
481 TotalProb+=IdentitySwapProb;
485 if(TotalProb > 1e-10)
488 TranslationProb /=TotalProb;
489 RotationProb /=TotalProb;
490 SpecialRotationProb/=TotalProb;
491 WidomProb /=TotalProb;
492 SwapProb /=TotalProb;
493 CBCFProb /=TotalProb;
494 ReinsertionProb /=TotalProb;
495 IdentitySwapProb /=TotalProb;
498 RotationProb += TranslationProb;
499 SpecialRotationProb += RotationProb;
500 WidomProb += SpecialRotationProb;
501 ReinsertionProb += WidomProb;
502 IdentitySwapProb += ReinsertionProb;
503 CBCFProb += IdentitySwapProb;
504 SwapProb += CBCFProb;
506 void PrintProbabilities()
508 printf(
"==================================================\n");
509 printf(
"ACCUMULATED Probabilities:\n");
510 printf(
"Translation Probability: %.5f\n", TranslationProb);
511 printf(
"Rotation Probability: %.5f\n", RotationProb);
512 printf(
"Special Rotation Probability: %.5f\n", SpecialRotationProb);
513 printf(
"Widom Probability: %.5f\n", WidomProb);
514 printf(
"Reinsertion Probability: %.5f\n", ReinsertionProb);
515 printf(
"Identity Swap Probability: %.5f\n", IdentitySwapProb);
516 printf(
"CBCF Swap Probability: %.5f\n", CBCFProb);
517 printf(
"Swap Probability: %.5f\n", SwapProb);
518 printf(
"Sum of Probabilities: %.5f\n", TotalProb);
519 printf(
"==================================================\n");
521 void RecordRosen(
double R,
int MoveType)
523 if(MoveType != INSERTION && MoveType != DELETION)
return;
525 Rosen[BlockID].Total.x += R;
526 Rosen[BlockID].Total.y += R * R;
527 Rosen[BlockID].Total.z += 1.0;
528 if(MoveType == INSERTION)
530 Rosen[BlockID].Insertion.x += R;
531 Rosen[BlockID].Insertion.y += R * R;
532 Rosen[BlockID].Insertion.z += 1.0;
534 else if(MoveType == DELETION)
536 Rosen[BlockID].Deletion.x += R;
537 Rosen[BlockID].Deletion.y += R * R;
538 Rosen[BlockID].Deletion.z += 1.0;
541 void ClearRosen(
size_t BlockID)
543 Rosen[BlockID].Total = {0.0, 0.0, 0.0};
544 Rosen[BlockID].Insertion = {0.0, 0.0, 0.0};
545 Rosen[BlockID].Deletion = {0.0, 0.0, 0.0};
546 Rosen[BlockID].WidomInsertion = {0.0, 0.0, 0.0};
548 void Record_Move_Total(
int MoveType)
552 case TRANSLATION: {TranslationTotal++;
break; }
553 case ROTATION: {RotationTotal++;
break; }
554 case SPECIAL_ROTATION: {SpecialRotationTotal++;
break; }
555 case INSERTION:
case SINGLE_INSERTION: {InsertionTotal++;
break; }
556 case DELETION:
case SINGLE_DELETION: {DeletionTotal++;
break; }
559 void Record_Move_Accept(
int MoveType)
563 case TRANSLATION: {TranslationAccepted++;
break; }
564 case ROTATION: {RotationAccepted++;
break; }
565 case SPECIAL_ROTATION: {SpecialRotationAccepted++;
break; }
566 case INSERTION:
case SINGLE_INSERTION: {InsertionAccepted++;
break; }
567 case DELETION:
case SINGLE_DELETION: {DeletionAccepted++;
break; }
844 size_t Total_Components;
846 int3 NumberofUnitCells;
847 size_t MoviesEvery = 5000;
848 size_t PrintStatsEvery = 5000;
851 size_t CURRENTCYCLE={0};
852 double DNNPredictTime={0.0};
853 double DNNFeatureTime={0.0};
854 double DNNGPUTime={0.0};
855 double DNNSortTime={0.0};
856 double DNNstdsortTime={0.0};
857 double DNNFeaturizationTime={0.0};
858 size_t TotalNumberOfMolecules;
859 size_t NumberOfFrameworks;
860 double Temperature={0.0};
865 std::vector<FRAMEWORK_COMPONENT_LISTS>FrameworkComponentDef;
871 std::vector<MoveEnergy> BookKeepEnergy;
872 std::vector<MoveEnergy> BookKeepEnergy_SQ;
903 void Copy_GPU_Data_To_Temp(
Atoms GPU_System,
size_t start,
size_t size)
905 cudaMemcpy(TempSystem.pos, &GPU_System.pos[start], size *
sizeof(double3), cudaMemcpyDeviceToHost);
906 cudaMemcpy(TempSystem.scale, &GPU_System.scale[start], size *
sizeof(
double), cudaMemcpyDeviceToHost);
907 cudaMemcpy(TempSystem.charge, &GPU_System.charge[start], size *
sizeof(
double), cudaMemcpyDeviceToHost);
908 cudaMemcpy(TempSystem.scaleCoul, &GPU_System.scaleCoul[start], size *
sizeof(
double), cudaMemcpyDeviceToHost);
909 cudaMemcpy(TempSystem.Type, &GPU_System.Type[start], size *
sizeof(
size_t), cudaMemcpyDeviceToHost);
910 cudaMemcpy(TempSystem.MolID, &GPU_System.MolID[start], size *
sizeof(
size_t), cudaMemcpyDeviceToHost);
915 double FrameworkEwald=0.0;
916 bool HasTailCorrection =
false;
917 bool ReadRestart =
false;
918 int RestartInputFileType = RASPA_RESTART;
919 bool Read_BoxsizeRestart =
false;
920 bool SingleSwap=
false;
925 bool UseDNNforHostGuest =
false;
926 size_t TranslationRotationDNNReject=0;
927 size_t ReinsertionDNNReject=0;
928 size_t InsertionDNNReject=0;
929 size_t DeletionDNNReject=0;
930 size_t SingleSwapDNNReject=0;
932 double SingleMoveDNNDrift=0.0;
933 double ReinsertionDNNDrift=0.0;
934 double InsertionDNNDrift=0.0;
935 double DeletionDNNDrift=0.0;
936 double SingleSwapDNNDrift=0.0;
937 double DNNDrift = 100000.0;
938 double DNNEnergyConversion;
939 bool UseAllegro =
false;
940 bool UseLCLin =
false;
944 std::vector<std::string>ModelName;
945 std::vector<std::string>InputLayer;
946 size_t* device_InverseIndexList;
947 bool* ConsiderThisAdsorbateAtom;
948 double* device_Distances;
950 std::vector<double2>EnergyAverage;
951 std::vector<bool> hasPartialCharge;
952 std::vector<bool> hasfractionalMolecule;
953 std::vector<LAMBDA> Lambda;
954 std::vector<TMMC> Tmmc;
955 std::vector<bool> rigid;
956 std::vector<double> ExclusionIntra;
957 std::vector<double> ExclusionAtom;
958 std::vector<std::string> MoleculeName;
959 std::vector<size_t> Moleculesize;
960 std::vector<size_t> NumberOfMolecule_for_Component;
961 std::vector<size_t> Allocate_size;
962 std::vector<size_t> NumberOfCreateMolecules;
963 std::vector<double> MolFraction;
964 std::vector<double> IdealRosenbluthWeight;
965 std::vector<double> FugacityCoeff;
967 std::vector<Move_Statistics>Moves;
968 std::vector<double3> MaxTranslation;
969 std::vector<double3> MaxRotation;
970 std::vector<double3> MaxSpecialRotation;
971 std::vector<double>Tc;
972 std::vector<double>Pc;
973 std::vector<double>Accentric;
974 std::vector<Tail>TailCorrection;
975 std::vector<double>MolecularWeight;
978 std::vector<size_t>NumberOfPseudoAtoms;
979 std::vector<std::vector<int2>>NumberOfPseudoAtomsForSpecies;
980 std::vector<std::complex<double>> eik_xy;
981 std::vector<std::complex<double>> eik_x;
982 std::vector<std::complex<double>> eik_y;
983 std::vector<std::complex<double>> eik_z;
984 std::vector<std::complex<double>> AdsorbateEik;
985 std::vector<std::complex<double>> FrameworkEik;
986 std::vector<std::complex<double>> tempEik;
987 size_t MatchMoleculeNameToComponentID(std::string Name)
989 for(
size_t i = 0; i < MoleculeName.size(); i++)
990 if(MoleculeName[i] == Name)
994 throw std::runtime_error(
"CANNOT find Molecule Names match " + Name +
" !!!! CHECK YOUR FILE!");
996 void UpdatePseudoAtoms(
int MoveType,
size_t component)
1000 case INSERTION:
case SINGLE_INSERTION:
case CBCF_INSERTION:
1002 for(
size_t i = 0; i < NumberOfPseudoAtomsForSpecies[component].size(); i++)
1004 size_t type = NumberOfPseudoAtomsForSpecies[component][i].x;
size_t Num = NumberOfPseudoAtomsForSpecies[component][i].y;
1005 NumberOfPseudoAtoms[type] += Num;
1009 case DELETION:
case SINGLE_DELETION:
case CBCF_DELETION:
1011 for(
size_t i = 0; i < NumberOfPseudoAtomsForSpecies[component].size(); i++)
1013 size_t type = NumberOfPseudoAtomsForSpecies[component][i].x;
size_t Num = NumberOfPseudoAtomsForSpecies[component][i].y;
1014 NumberOfPseudoAtoms[type] -= Num;
1018 case TRANSLATION:
case ROTATION:
case REINSERTION:
case CBCF_LAMBDACHANGE: