Unverified Commit 0e9ef3f8 authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

setVelocitiesToTemperature() works with massless Drude particles (#4356)

parent d80ddda3
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2008-2022 Stanford University and the Authors. * * Portions copyright (c) 2008-2023 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -123,6 +123,10 @@ vector<Vec3> assignDrudeVelocities(const System &system, double temperature, dou ...@@ -123,6 +123,10 @@ vector<Vec3> assignDrudeVelocities(const System &system, double temperature, dou
velocities[atom1] = comVelocity - fracM2 * relVelocity; velocities[atom1] = comVelocity - fracM2 * relVelocity;
velocities[atom2] = comVelocity + fracM1 * relVelocity; velocities[atom2] = comVelocity + fracM1 * relVelocity;
} }
else if (mass2 != 0) {
double velocityScale = sqrt(BOLTZ*temperature/mass2);
velocities[atom2] = Vec3(randoms[nextRandom++], randoms[nextRandom++], randoms[nextRandom++])*velocityScale;
}
} }
return velocities; return velocities;
} }
......
...@@ -132,7 +132,7 @@ void testWater() { ...@@ -132,7 +132,7 @@ void testWater() {
} }
} }
void testInitialTemperature() { void testInitialTemperature(double drudeMass) {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numRealParticles = 50000; const int numRealParticles = 50000;
const int numParticles = 2 * numRealParticles; const int numParticles = 2 * numRealParticles;
...@@ -140,7 +140,6 @@ void testInitialTemperature() { ...@@ -140,7 +140,6 @@ void testInitialTemperature() {
const double targetTemperature = 300; const double targetTemperature = 300;
const double drudeTemperature = 0; const double drudeTemperature = 0;
const double realMass = 10; const double realMass = 10;
const double drudeMass = 1;
System system; System system;
OpenMM_SFMT::SFMT sfmt; OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt); init_gen_rand(0, sfmt);
...@@ -196,7 +195,8 @@ int main(int argc, char* argv[]) { ...@@ -196,7 +195,8 @@ int main(int argc, char* argv[]) {
setupKernels(argc, argv); setupKernels(argc, argv);
testWater(); testWater();
runPlatformTests(); runPlatformTests();
testInitialTemperature(); testInitialTemperature(0);
testInitialTemperature(1);
} }
catch(const std::exception& e) { catch(const std::exception& e) {
std::cout << "exception: " << e.what() << std::endl; std::cout << "exception: " << e.what() << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment