From e266a2082f8670ba35e8a4df8217e92b5ccdb414 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Jul 2022 16:01:47 -0400 Subject: [PATCH 1/3] New method of correcting for imaging in diffusion that is less memory hungry and more accurate when compared to unwrap --- src/Action_Diffusion.cpp | 47 ++++++++++++++++++++-------------------- src/Action_Diffusion.h | 1 - 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Action_Diffusion.cpp b/src/Action_Diffusion.cpp index d176d41eae..e9cf89186b 100644 --- a/src/Action_Diffusion.cpp +++ b/src/Action_Diffusion.cpp @@ -237,9 +237,6 @@ Action::RetType Action_Diffusion::Setup(ActionSetup& setup) { } else mprintf("\tImaging disabled.\n"); - // Allocate the delta array - delta_.assign( mask_.Nselected() * 3, 0.0 ); - // Reserve space for the previous coordinates array previous_.reserve( mask_.Nselected() * 3 ); @@ -329,10 +326,14 @@ Action::RetType Action_Diffusion::DoAction(int frameNum, ActionFrame& frm) { double avgx = 0.0; double avgy = 0.0; double avgz = 0.0; - unsigned int idx = 0; // Index into previous_ and delta_ + unsigned int idx = 0; // Index into previous_ + double fixedXYZ[3]; for (AtomMask::const_iterator at = mask_.begin(); at != mask_.end(); ++at, idx += 3) { // Get current and initial coords for this atom. const double* XYZ = frm.Frm().XYZ(*at); + fixedXYZ[0] = XYZ[0]; + fixedXYZ[1] = XYZ[1]; + fixedXYZ[2] = XYZ[2]; const double* iXYZ = initial_.XYZ(*at); // Calculate distance from initial position. double delx, dely, delz; @@ -345,17 +346,17 @@ Action::RetType Action_Diffusion::DoAction(int frameNum, ActionFrame& frm) { // If the particle moved more than half the box, assume it was imaged // and adjust the distance of the total movement with respect to the // original frame. - if (delx > boxcenter_[0]) delta_[idx ] -= frm.Frm().BoxCrd().Param(Box::X); - else if (delx < -boxcenter_[0]) delta_[idx ] += frm.Frm().BoxCrd().Param(Box::X); - if (dely > boxcenter_[1]) delta_[idx+1] -= frm.Frm().BoxCrd().Param(Box::Y); - else if (dely < -boxcenter_[1]) delta_[idx+1] += frm.Frm().BoxCrd().Param(Box::Y); - if (delz > boxcenter_[2]) delta_[idx+2] -= frm.Frm().BoxCrd().Param(Box::Z); - else if (delz < -boxcenter_[2]) delta_[idx+2] += frm.Frm().BoxCrd().Param(Box::Z); + if (delx > boxcenter_[0]) fixedXYZ[0] -= frm.Frm().BoxCrd().Param(Box::X); + else if (delx < -boxcenter_[0]) fixedXYZ[0] += frm.Frm().BoxCrd().Param(Box::X); + if (dely > boxcenter_[1]) fixedXYZ[1] -= frm.Frm().BoxCrd().Param(Box::Y); + else if (dely < -boxcenter_[1]) fixedXYZ[1] += frm.Frm().BoxCrd().Param(Box::Y); + if (delz > boxcenter_[2]) fixedXYZ[2] -= frm.Frm().BoxCrd().Param(Box::Z); + else if (delz < -boxcenter_[2]) fixedXYZ[2] += frm.Frm().BoxCrd().Param(Box::Z); // Calculate the distance between this "fixed" coordinate // and the reference (initial) frame. - delx = XYZ[0] + delta_[idx ] - iXYZ[0]; - dely = XYZ[1] + delta_[idx+1] - iXYZ[1]; - delz = XYZ[2] + delta_[idx+2] - iXYZ[2]; + delx = fixedXYZ[0] - iXYZ[0]; + dely = fixedXYZ[1] - iXYZ[1]; + delz = fixedXYZ[2] - iXYZ[2]; } else if ( imageOpt_.ImagingType() == ImageOption::NONORTHO ) { // Non-orthorhombic imaging // Calculate distance to previous frames coordinates. @@ -396,16 +397,16 @@ Action::RetType Action_Diffusion::DoAction(int frameNum, ActionFrame& frm) { } } } - // Update the delta for this atom - delta_[idx ] += minCurr[0] - XYZ[0]; // cCart - delta_[idx+1] += minCurr[1] - XYZ[1]; - delta_[idx+2] += minCurr[2] - XYZ[2]; + // minCurr contains the shortest imaged position from previous coords + fixedXYZ[0] = minCurr[0]; + fixedXYZ[1] = minCurr[1]; + fixedXYZ[2] = minCurr[2]; } // Calculate the distance between this "fixed" coordinate // and the reference (initial) frame. - delx = XYZ[0] + delta_[idx ] - iXYZ[0]; - dely = XYZ[1] + delta_[idx+1] - iXYZ[1]; - delz = XYZ[2] + delta_[idx+2] - iXYZ[2]; + delx = fixedXYZ[0] - iXYZ[0]; + dely = fixedXYZ[1] - iXYZ[1]; + delz = fixedXYZ[2] - iXYZ[2]; } else { // No imaging. Calculate distance from current position to initial position. delx = XYZ[0] - iXYZ[0]; @@ -437,9 +438,9 @@ Action::RetType Action_Diffusion::DoAction(int frameNum, ActionFrame& frm) { atom_a_[*at]->Add(frameNum, &fval); } // Update the previous coordinate set to match the current coordinates - previous_[idx ] = XYZ[0]; - previous_[idx+1] = XYZ[1]; - previous_[idx+2] = XYZ[2]; + previous_[idx ] = fixedXYZ[0]; + previous_[idx+1] = fixedXYZ[1]; + previous_[idx+2] = fixedXYZ[2]; } // END loop over selected atoms // Calc averages double dNselected = 1.0 / (double)mask_.Nselected(); diff --git a/src/Action_Diffusion.h b/src/Action_Diffusion.h index fd95ec7106..95430aedff 100644 --- a/src/Action_Diffusion.h +++ b/src/Action_Diffusion.h @@ -42,7 +42,6 @@ class Action_Diffusion : public Action { DataSet* diffInter_; ///< Hold MSD vs time line intercepts. DataSet* diffCorrl_; ///< Hold MSD vs time line correlation. int debug_; - Darray delta_; ///< Hold current distances from initial frame for selected atoms AtomMask mask_; ///< Selected atoms DataFile* outputx_; DataFile* outputy_; From 8a12c70e307bca04fe5713385af8964448693ca9 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Sat, 30 Jul 2022 19:05:01 -0400 Subject: [PATCH 2/3] Update output for new imaging correction --- test/Test_Diffusion/DC.dat.save | 8 +-- test/Test_Diffusion/Nonortho.agr.save | 74 ++++++++++++------------- test/Test_Diffusion/Nonortho.dat.save | 8 +-- test/Test_Diffusion/WAT_O.agr.save | 78 +++++++++++++-------------- 4 files changed, 84 insertions(+), 84 deletions(-) diff --git a/test/Test_Diffusion/DC.dat.save b/test/Test_Diffusion/DC.dat.save index 88ef434a70..bf90f4dad5 100644 --- a/test/Test_Diffusion/DC.dat.save +++ b/test/Test_Diffusion/DC.dat.save @@ -1,5 +1,5 @@ #Set WAT_O[D] WAT_O[Slope] WAT_O[Intercept] WAT_O[Corr] WAT_O[Label] - 1 3.0086 1.8052 0.3773 0.9993 WAT_O_AvgDr - 2 3.2638 0.6528 0.1261 0.9993 WAT_O_AvgDx - 3 2.7805 0.5561 0.1342 0.9987 WAT_O_AvgDy - 4 2.9816 0.5963 0.1171 0.9991 WAT_O_AvgDz + 1 3.0108 1.8065 0.3730 0.9993 WAT_O_AvgDr + 2 3.2667 0.6533 0.1242 0.9993 WAT_O_AvgDx + 3 2.7822 0.5564 0.1329 0.9987 WAT_O_AvgDy + 4 2.9836 0.5967 0.1159 0.9991 WAT_O_AvgDz diff --git a/test/Test_Diffusion/Nonortho.agr.save b/test/Test_Diffusion/Nonortho.agr.save index 6d469707b2..2a31b96f68 100644 --- a/test/Test_Diffusion/Nonortho.agr.save +++ b/test/Test_Diffusion/Nonortho.agr.save @@ -8,63 +8,63 @@ @type xy 0.000 0.0000 1.000 2.3161 - 2.000 4.4277 - 3.000 6.5507 - 4.000 8.3064 - 5.000 10.0601 - 6.000 11.7059 - 7.000 13.6213 - 8.000 15.1883 - 9.000 17.0717 + 2.000 4.4288 + 3.000 6.5496 + 4.000 8.3059 + 5.000 10.0595 + 6.000 11.7056 + 7.000 13.6259 + 8.000 15.2001 + 9.000 17.0681 @ s1 legend "WAT_O[X]" @target G0.S1 @type xy 0.000 0.0000 1.000 0.7624 - 2.000 1.4227 - 3.000 2.1385 - 4.000 2.6632 - 5.000 3.2397 + 2.000 1.4231 + 3.000 2.1383 + 4.000 2.6631 + 5.000 3.2395 6.000 3.7799 - 7.000 4.4781 - 8.000 4.9872 - 9.000 5.5655 + 7.000 4.4798 + 8.000 4.9914 + 9.000 5.5646 @ s2 legend "WAT_O[Y]" @target G0.S2 @type xy 0.000 0.0000 1.000 0.7638 - 2.000 1.4841 - 3.000 2.2502 - 4.000 2.8063 - 5.000 3.3556 - 6.000 3.8485 - 7.000 4.3937 - 8.000 4.9555 - 9.000 5.6009 + 2.000 1.4845 + 3.000 2.2497 + 4.000 2.8061 + 5.000 3.3553 + 6.000 3.8484 + 7.000 4.3951 + 8.000 4.9591 + 9.000 5.5997 @ s3 legend "WAT_O[Z]" @target G0.S3 @type xy 0.000 0.0000 1.000 0.7899 - 2.000 1.5209 - 3.000 2.1620 - 4.000 2.8368 - 5.000 3.4649 + 2.000 1.5212 + 3.000 2.1616 + 4.000 2.8367 + 5.000 3.4647 6.000 4.0774 - 7.000 4.7495 - 8.000 5.2456 - 9.000 5.9052 + 7.000 4.7510 + 8.000 5.2496 + 9.000 5.9038 @ s4 legend "WAT_O[A]" @target G0.S4 @type xy 0.000 0.0000 1.000 1.5219 - 2.000 2.1042 - 3.000 2.5594 - 4.000 2.8821 - 5.000 3.1718 + 2.000 2.1045 + 3.000 2.5592 + 4.000 2.8820 + 5.000 3.1717 6.000 3.4214 - 7.000 3.6907 - 8.000 3.8972 - 9.000 4.1318 + 7.000 3.6913 + 8.000 3.8987 + 9.000 4.1314 diff --git a/test/Test_Diffusion/Nonortho.dat.save b/test/Test_Diffusion/Nonortho.dat.save index 34342d8bbf..d7c571571d 100644 --- a/test/Test_Diffusion/Nonortho.dat.save +++ b/test/Test_Diffusion/Nonortho.dat.save @@ -1,5 +1,5 @@ #Set WAT_O[D] WAT_O[Slope] WAT_O[Intercept] WAT_O[Corr] WAT_O[Label] - 1 3.1004 1.8602 0.5538 0.9987 WAT_O_AvgDr - 2 3.0437 0.6087 0.1644 0.9989 WAT_O_AvgDx - 3 3.0195 0.6039 0.2283 0.9974 WAT_O_AvgDy - 4 3.2380 0.6476 0.1610 0.9991 WAT_O_AvgDz + 1 3.1011 1.8607 0.5530 0.9987 WAT_O_AvgDr + 2 3.0445 0.6089 0.1641 0.9989 WAT_O_AvgDx + 3 3.0201 0.6040 0.2281 0.9974 WAT_O_AvgDy + 4 3.2387 0.6477 0.1608 0.9991 WAT_O_AvgDz diff --git a/test/Test_Diffusion/WAT_O.agr.save b/test/Test_Diffusion/WAT_O.agr.save index 5b0abe9e4f..fdc17cb510 100644 --- a/test/Test_Diffusion/WAT_O.agr.save +++ b/test/Test_Diffusion/WAT_O.agr.save @@ -8,63 +8,63 @@ @type xy 0.000 0.0000 1.000 2.2649 - 2.000 4.2297 - 3.000 5.9000 - 4.000 7.8899 - 5.000 9.3842 - 6.000 10.9382 - 7.000 12.8945 - 8.000 14.8844 - 9.000 16.6205 + 2.000 4.2294 + 3.000 5.9011 + 4.000 7.8844 + 5.000 9.3786 + 6.000 10.9408 + 7.000 12.8919 + 8.000 14.8926 + 9.000 16.6393 @ s1 legend "WAT_O[X]" @target G0.S1 @type xy 0.000 0.0000 1.000 0.7846 - 2.000 1.5184 - 3.000 2.1000 - 4.000 2.8321 - 5.000 3.4484 - 6.000 3.9755 - 7.000 4.6223 - 8.000 5.3717 - 9.000 5.9813 + 2.000 1.5183 + 3.000 2.1005 + 4.000 2.8300 + 5.000 3.4460 + 6.000 3.9768 + 7.000 4.6214 + 8.000 5.3753 + 9.000 5.9894 @ s2 legend "WAT_O[Y]" @target G0.S2 @type xy 0.000 0.0000 1.000 0.7319 - 2.000 1.3339 - 3.000 1.8401 - 4.000 2.4787 - 5.000 2.8731 - 6.000 3.3699 - 7.000 4.0099 - 8.000 4.5213 - 9.000 5.2075 + 2.000 1.3338 + 3.000 1.8404 + 4.000 2.4768 + 5.000 2.8712 + 6.000 3.3703 + 7.000 4.0089 + 8.000 4.5234 + 9.000 5.2127 @ s3 legend "WAT_O[Z]" @target G0.S3 @type xy 0.000 0.0000 1.000 0.7484 - 2.000 1.3774 - 3.000 1.9599 - 4.000 2.5791 - 5.000 3.0626 - 6.000 3.5928 - 7.000 4.2623 - 8.000 4.9914 - 9.000 5.4317 + 2.000 1.3773 + 3.000 1.9602 + 4.000 2.5777 + 5.000 3.0614 + 6.000 3.5936 + 7.000 4.2616 + 8.000 4.9939 + 9.000 5.4373 @ s4 legend "WAT_O[A]" @target G0.S4 @type xy 0.000 0.0000 1.000 1.5050 2.000 2.0566 - 3.000 2.4290 - 4.000 2.8089 - 5.000 3.0634 - 6.000 3.3073 - 7.000 3.5909 - 8.000 3.8580 - 9.000 4.0768 + 3.000 2.4292 + 4.000 2.8079 + 5.000 3.0625 + 6.000 3.3077 + 7.000 3.5905 + 8.000 3.8591 + 9.000 4.0791 From c6e95c9aefe0cc4e180aad83f8647155ce07bf41 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Sat, 30 Jul 2022 19:08:02 -0400 Subject: [PATCH 3/3] 6.13.0. Minor version bump for change to diffusion imaging correction compared to unwrap. --- src/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Version.h b/src/Version.h index 93052a137a..8fa4222147 100644 --- a/src/Version.h +++ b/src/Version.h @@ -12,7 +12,7 @@ * Whenever a number that precedes is incremented, all subsequent * numbers should be reset to 0. */ -#define CPPTRAJ_INTERNAL_VERSION "V6.12.2" +#define CPPTRAJ_INTERNAL_VERSION "V6.13.0" /// PYTRAJ relies on this #define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION #endif