1#include "mc_utilities.h"
9 double NMol = SystemComponents.NumberOfMolecule_for_Component[SelectedComponent];
10 if(SystemComponents.hasfractionalMolecule[SelectedComponent]) NMol--;
16 for(
size_t ijk = 0; ijk < SystemComponents.Total_Components; ijk++)
17 Atomsize += SystemComponents.Moleculesize[ijk] * SystemComponents.NumberOfMolecule_for_Component[ijk];
18 size_t Molsize = SystemComponents.Moleculesize[SelectedComponent];
22 throw std::runtime_error(
"Molecule size is greater than allocated size, Why so big?\n");
24 size_t start_position = SelectedMolInComponent*SystemComponents.Moleculesize[SelectedComponent];
26 SystemComponents.Moves[SelectedComponent].Record_Move_Total(MoveType);
27 double3 MaxChange = {0.0, 0.0, 0.0};
28 bool CheckOverlap =
true;
33 Do_New =
true; Do_Old =
true;
34 MaxChange = SystemComponents.MaxTranslation[SelectedComponent];
39 Do_New =
true; Do_Old =
true;
40 MaxChange = SystemComponents.MaxRotation[SelectedComponent];
43 case SPECIAL_ROTATION:
45 Do_New =
true; Do_Old =
true;
46 MaxChange = SystemComponents.MaxSpecialRotation[SelectedComponent];
52 case SINGLE_INSERTION:
64 if(!Do_New && !Do_Old)
throw std::runtime_error(
"Doing Nothing For Single Particle Move?\n");
67 Random.Check(Molsize);
68 get_new_position<<<1, Molsize>>>(Sims, FF, start_position, SelectedComponent, MaxChange, Random.device_random, Random.offset, MoveType);
69 Random.Update(Molsize);
74 size_t NHostAtom = 0;
size_t NGuestAtom = 0;
75 for(
size_t i = 0; i < SystemComponents.NComponents.y; i++)
76 NHostAtom += SystemComponents.Moleculesize[i] * SystemComponents.NumberOfMolecule_for_Component[i];
77 for(
size_t i = SystemComponents.NComponents.y; i < SystemComponents.NComponents.x; i++)
78 NGuestAtom+= SystemComponents.Moleculesize[i] * SystemComponents.NumberOfMolecule_for_Component[i];
81 size_t NCrossAtom = NHostAtom;
82 if(SelectedComponent < SystemComponents.NComponents.y)
83 NCrossAtom = NGuestAtom;
84 size_t HH_Nthread=0;
size_t HH_Nblock=0; Setup_threadblock(NHostAtom * Molsize, &HH_Nblock, &HH_Nthread);
85 size_t HG_Nthread=0;
size_t HG_Nblock=0; Setup_threadblock(NCrossAtom * Molsize, &HG_Nblock, &HG_Nthread);
86 size_t GG_Nthread=0;
size_t GG_Nblock=0; Setup_threadblock(NGuestAtom * Molsize, &GG_Nblock, &GG_Nthread);
88 size_t SameTypeNthread = 0;
89 if(SelectedComponent < SystemComponents.NComponents.y)
90 {GG_Nthread = 0; GG_Nblock = 0; SameTypeNthread = HH_Nthread; }
92 {HH_Nthread = 0; HH_Nblock = 0; SameTypeNthread = GG_Nthread; }
94 size_t Nthread = std::max(SameTypeNthread, HG_Nthread);
95 size_t Total_Nblock = HH_Nblock + HG_Nblock + GG_Nblock;
97 int3 NBlocks = {(int) HH_Nblock, (
int) HG_Nblock, (int) GG_Nblock};
102 Calculate_Single_Body_Energy_SEPARATE_HostGuest_VDWReal<<<Total_Nblock, Nthread, Nthread * 2 *
sizeof(double)>>>(Sims.Box, Sims.d_a, Sims.Old, Sims.New, FF, Sims.Blocksum, SelectedComponent, Atomsize, Molsize, Sims.device_flag, NBlocks, Do_New, Do_Old, SystemComponents.NComponents);
104 cudaMemcpy(SystemComponents.flag, Sims.device_flag,
sizeof(
bool), cudaMemcpyDeviceToHost);
106 MoveEnergy tot;
bool Accept =
false;
double Pacc = 0.0;
107 if(!SystemComponents.flag[0] || !CheckOverlap)
109 double BlockResult[Total_Nblock + Total_Nblock];
110 cudaMemcpy(BlockResult, Sims.Blocksum, 2 * Total_Nblock *
sizeof(
double), cudaMemcpyDeviceToHost);
113 for(
size_t i = 0; i < HH_Nblock; i++)
115 tot.HHVDW += BlockResult[i];
116 tot.HHReal+= BlockResult[i + Total_Nblock];
119 for(
size_t i = HH_Nblock; i < HH_Nblock + HG_Nblock; i++)
121 tot.HGVDW += BlockResult[i];
122 tot.HGReal+= BlockResult[i + Total_Nblock];
125 for(
size_t i = HH_Nblock + HG_Nblock; i < Total_Nblock; i++)
127 tot.GGVDW += BlockResult[i];
128 tot.GGReal+= BlockResult[i + Total_Nblock];
139 bool EwaldPerformed =
false;
140 if(!FF.noCharges && SystemComponents.hasPartialCharge[SelectedComponent])
142 double2 newScale = SystemComponents.Lambda[SelectedComponent].SET_SCALE(1.0);
143 double2 EwaldE = GPU_EwaldDifference_General(Sims.Box, Sims.d_a, Sims.New, Sims.Old, FF, Sims.Blocksum, SystemComponents, SelectedComponent, MoveType, 0, newScale);
146 tot.GGEwaldE = EwaldE.x;
147 tot.HGEwaldE = EwaldE.y;
151 tot.HHEwaldE = EwaldE.x;
152 tot.HGEwaldE = EwaldE.y;
155 EwaldPerformed =
true;
157 if(SystemComponents.UseDNNforHostGuest)
160 if(!EwaldPerformed) Prepare_DNN_InitialPositions(Sims.d_a, Sims.New, Sims.Old, SystemComponents, SelectedComponent, MoveType, 0);
161 tot.DNN_E = DNN_Prediction_Move(SystemComponents, Sims, SelectedComponent, MoveType);
162 double correction = tot.DNN_Correction();
163 if(fabs(correction) > SystemComponents.DNNDrift)
168 case TRANSLATION:
case ROTATION:
170 SystemComponents.TranslationRotationDNNReject ++;
break;
172 case SINGLE_INSERTION:
case SINGLE_DELETION:
174 SystemComponents.SingleSwapDNNReject ++;
break;
177 WriteOutliers(SystemComponents, Sims, NEW, tot, correction);
178 WriteOutliers(SystemComponents, Sims, OLD, tot, correction);
182 SystemComponents.SingleMoveDNNDrift += fabs(correction);
185 double preFactor = GetPrefactor(SystemComponents, Sims, SelectedComponent, MoveType);
186 Pacc = preFactor * std::exp(-SystemComponents.Beta * tot.total());
189 if(MoveType == SINGLE_INSERTION || MoveType == SINGLE_DELETION)
191 SystemComponents.Tmmc[SelectedComponent].ApplyWLBias(preFactor, NMol, MoveType);
192 SystemComponents.Tmmc[SelectedComponent].ApplyTMBias(preFactor, NMol, MoveType);
196 if(Get_Uniform_Random() < preFactor * std::exp(-SystemComponents.Beta * tot.total())) Accept =
true;
205 case TRANSLATION:
case ROTATION:
case SPECIAL_ROTATION:
209 update_translation_position<<<1,Molsize>>>(Sims.d_a, Sims.New, start_position, SelectedComponent);
210 SystemComponents.Moves[SelectedComponent].Record_Move_Accept(MoveType);
211 if(!FF.noCharges && SystemComponents.hasPartialCharge[SelectedComponent])
213 Update_Ewald_Vector(Sims.Box,
false, SystemComponents, SelectedComponent);
217 SystemComponents.Tmmc[SelectedComponent].Update(1.0, NMol, MoveType);
220 case SINGLE_INSERTION:
222 SystemComponents.Tmmc[SelectedComponent].TreatAccOutofBound(Accept, NMol, MoveType);
225 SystemComponents.Moves[SelectedComponent].Record_Move_Accept(MoveType);
226 AcceptInsertion(SystemComponents, Sims, SelectedComponent, 0, FF.noCharges, SINGLE_INSERTION);
229 SystemComponents.Tmmc[SelectedComponent].Update(Pacc, NMol, MoveType);
232 case SINGLE_DELETION:
234 SystemComponents.Tmmc[SelectedComponent].TreatAccOutofBound(Accept, NMol, MoveType);
237 SystemComponents.Moves[SelectedComponent].Record_Move_Accept(MoveType);
238 size_t UpdateLocation = SelectedMolInComponent * SystemComponents.Moleculesize[SelectedComponent];
239 AcceptDeletion(SystemComponents, Sims, SelectedComponent, UpdateLocation, SelectedMolInComponent, FF.noCharges);
242 SystemComponents.Tmmc[SelectedComponent].Update(Pacc, NMol, MoveType);
Definition data_struct.h:843
Definition data_struct.h:794
Definition data_struct.h:615
Definition data_struct.h:1053
Definition data_struct.h:1027
Definition data_struct.h:1044