Unverified Commit 78902bed authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Optimize updateParametersInContext() (#4610)

* Optimize CustomNonbondedForce.updateParametersInContext()

* Optimized uploading changed values to GPU

* Optimized updateParametersInContext() for lots of bonded forces

* Optimized updateParametersInContext() for CustomExternalForce

* Optimized updateParametersInContext() for NonbondedForce

* Code changes for HIP platform
parent 66064fac
...@@ -323,8 +323,10 @@ public: ...@@ -323,8 +323,10 @@ public:
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the HarmonicBondForce to copy the parameters from * @param force the HarmonicBondForce to copy the parameters from
* @param firstBond the index of the first bond whose parameters might have changed
* @param lastBond the index of the last bond whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const HarmonicBondForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const HarmonicBondForce& force, int firstBond, int lastBond) = 0;
}; };
/** /**
...@@ -358,8 +360,10 @@ public: ...@@ -358,8 +360,10 @@ public:
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the CustomBondForce to copy the parameters from * @param force the CustomBondForce to copy the parameters from
* @param firstBond the index of the first bond whose parameters might have changed
* @param lastBond the index of the last bond whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const CustomBondForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const CustomBondForce& force, int firstBond, int lastBond) = 0;
}; };
/** /**
...@@ -393,8 +397,10 @@ public: ...@@ -393,8 +397,10 @@ public:
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the HarmonicAngleForce to copy the parameters from * @param force the HarmonicAngleForce to copy the parameters from
* @param firstAngle the index of the first bond whose parameters might have changed
* @param lastAngle the index of the last bond whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const HarmonicAngleForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const HarmonicAngleForce& force, int firstAngle, int lastAngle) = 0;
}; };
/** /**
...@@ -428,8 +434,10 @@ public: ...@@ -428,8 +434,10 @@ public:
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the CustomAngleForce to copy the parameters from * @param force the CustomAngleForce to copy the parameters from
* @param firstAngle the index of the first bond whose parameters might have changed
* @param lastAngle the index of the last bond whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const CustomAngleForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const CustomAngleForce& force, int firstAngle, int lastAngle) = 0;
}; };
/** /**
...@@ -461,10 +469,12 @@ public: ...@@ -461,10 +469,12 @@ public:
/** /**
* Copy changed parameters over to a context. * Copy changed parameters over to a context.
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the PeriodicTorsionForce to copy the parameters from * @param force the PeriodicTorsionForce to copy the parameters from
* @param firstTorsion the index of the first torsion whose parameters might have changed
* @param lastTorsion the index of the last torsion whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const PeriodicTorsionForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const PeriodicTorsionForce& force, int firstTorsion, int lastTorsion) = 0;
}; };
/** /**
...@@ -566,10 +576,12 @@ public: ...@@ -566,10 +576,12 @@ public:
/** /**
* Copy changed parameters over to a context. * Copy changed parameters over to a context.
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the CustomTorsionForce to copy the parameters from * @param force the CustomTorsionForce to copy the parameters from
* @param firstTorsion the index of the first torsion whose parameters might have changed
* @param lastTorsion the index of the last torsion whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const CustomTorsionForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const CustomTorsionForce& force, int firstTorsion, int lastTorsion) = 0;
}; };
/** /**
...@@ -611,10 +623,14 @@ public: ...@@ -611,10 +623,14 @@ public:
/** /**
* Copy changed parameters over to a context. * Copy changed parameters over to a context.
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the NonbondedForce to copy the parameters from * @param force the NonbondedForce to copy the parameters from
* @param firstParticle the index of the first particle whose parameters might have changed
* @param lastParticle the index of the last particle whose parameters might have changed
* @param firstException the index of the first exception whose parameters might have changed
* @param lastException the index of the last exception whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const NonbondedForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const NonbondedForce& force, int firstParticle, int lastParticle, int firstException, int lastException) = 0;
/** /**
* Get the parameters being used for PME. * Get the parameters being used for PME.
* *
...@@ -671,8 +687,10 @@ public: ...@@ -671,8 +687,10 @@ public:
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the CustomNonbondedForce to copy the parameters from * @param force the CustomNonbondedForce to copy the parameters from
* @param firstParticle the index of the first particle whose parameters might have changed
* @param lastParticle the index of the last particle whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const CustomNonbondedForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const CustomNonbondedForce& force, int firstParticle, int lastParticle) = 0;
}; };
/** /**
...@@ -779,10 +797,12 @@ public: ...@@ -779,10 +797,12 @@ public:
/** /**
* Copy changed parameters over to a context. * Copy changed parameters over to a context.
* *
* @param context the context to copy parameters to * @param context the context to copy parameters to
* @param force the CustomExternalForce to copy the parameters from * @param force the CustomExternalForce to copy the parameters from
* @param firstParticle the index of the first particle whose parameters might have changed
* @param lastParticle the index of the last particle whose parameters might have changed
*/ */
virtual void copyParametersToContext(ContextImpl& context, const CustomExternalForce& force) = 0; virtual void copyParametersToContext(ContextImpl& context, const CustomExternalForce& force, int firstParticle, int lastParticle) = 0;
}; };
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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) 2010-2016 Stanford University and the Authors. * * Portions copyright (c) 2010-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -263,6 +263,7 @@ private: ...@@ -263,6 +263,7 @@ private:
std::vector<AngleInfo> angles; std::vector<AngleInfo> angles;
std::vector<int> energyParameterDerivatives; std::vector<int> energyParameterDerivatives;
bool usePeriodic; bool usePeriodic;
mutable int numContexts, firstChangedAngle, lastChangedAngle;
}; };
/** /**
......
...@@ -260,6 +260,7 @@ private: ...@@ -260,6 +260,7 @@ private:
std::vector<BondInfo> bonds; std::vector<BondInfo> bonds;
std::vector<int> energyParameterDerivatives; std::vector<int> energyParameterDerivatives;
bool usePeriodic; bool usePeriodic;
mutable int numContexts, firstChangedBond, lastChangedBond;
}; };
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -240,6 +240,7 @@ private: ...@@ -240,6 +240,7 @@ private:
std::vector<ParticleParameterInfo> parameters; std::vector<ParticleParameterInfo> parameters;
std::vector<GlobalParameterInfo> globalParameters; std::vector<GlobalParameterInfo> globalParameters;
std::vector<ParticleInfo> particles; std::vector<ParticleInfo> particles;
mutable int numContexts, firstChangedParticle, lastChangedParticle;
}; };
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -590,6 +590,7 @@ private: ...@@ -590,6 +590,7 @@ private:
std::vector<ComputedValueInfo> computedValues; std::vector<ComputedValueInfo> computedValues;
std::vector<InteractionGroupInfo> interactionGroups; std::vector<InteractionGroupInfo> interactionGroups;
std::vector<int> energyParameterDerivatives; std::vector<int> energyParameterDerivatives;
mutable int numContexts, firstChangedParticle, lastChangedParticle;
}; };
/** /**
......
...@@ -276,6 +276,7 @@ private: ...@@ -276,6 +276,7 @@ private:
std::vector<TorsionInfo> torsions; std::vector<TorsionInfo> torsions;
std::vector<int> energyParameterDerivatives; std::vector<int> energyParameterDerivatives;
bool usePeriodic; bool usePeriodic;
mutable int numContexts, firstChangedTorsion, lastChangedTorsion;
}; };
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2016 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -119,6 +119,7 @@ private: ...@@ -119,6 +119,7 @@ private:
class AngleInfo; class AngleInfo;
std::vector<AngleInfo> angles; std::vector<AngleInfo> angles;
bool usePeriodic; bool usePeriodic;
mutable int numContexts, firstChangedAngle, lastChangedAngle;
}; };
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2016 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -117,6 +117,7 @@ private: ...@@ -117,6 +117,7 @@ private:
class BondInfo; class BondInfo;
std::vector<BondInfo> bonds; std::vector<BondInfo> bonds;
bool usePeriodic; bool usePeriodic;
mutable int numContexts, firstChangedBond, lastChangedBond;
}; };
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -637,6 +637,7 @@ private: ...@@ -637,6 +637,7 @@ private:
std::vector<ParticleOffsetInfo> particleOffsets; std::vector<ParticleOffsetInfo> particleOffsets;
std::vector<ExceptionOffsetInfo> exceptionOffsets; std::vector<ExceptionOffsetInfo> exceptionOffsets;
std::map<std::pair<int, int>, int> exceptionMap; std::map<std::pair<int, int>, int> exceptionMap;
mutable int numContexts, firstChangedParticle, lastChangedParticle, firstChangedException, lastChangedException;
}; };
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2016 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -126,6 +126,7 @@ private: ...@@ -126,6 +126,7 @@ private:
class PeriodicTorsionInfo; class PeriodicTorsionInfo;
std::vector<PeriodicTorsionInfo> periodicTorsions; std::vector<PeriodicTorsionInfo> periodicTorsions;
bool usePeriodic; bool usePeriodic;
mutable int numContexts, firstChangedTorsion, lastChangedTorsion;
}; };
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstAngle, int lastAngle);
private: private:
const CustomAngleForce& owner; const CustomAngleForce& owner;
Kernel kernel; Kernel kernel;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2009 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -60,7 +60,7 @@ public: ...@@ -60,7 +60,7 @@ public:
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
std::vector<std::pair<int, int> > getBondedParticles() const; std::vector<std::pair<int, int> > getBondedParticles() const;
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstBond, int lastBond);
private: private:
const CustomBondForce& owner; const CustomBondForce& owner;
Kernel kernel; Kernel kernel;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstParticle, int lastParticle);
private: private:
const CustomExternalForce& owner; const CustomExternalForce& owner;
Kernel kernel; Kernel kernel;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstParticle, int lastParticle);
/** /**
* Prepare for computing the long range correction. This function pre-computes anything * Prepare for computing the long range correction. This function pre-computes anything
* that depends only on the Force (such as particle parameters) but not on information in * that depends only on the Force (such as particle parameters) but not on information in
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstTorsion, int lastTorsion);
private: private:
const CustomTorsionForce& owner; const CustomTorsionForce& owner;
Kernel kernel; Kernel kernel;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstAngle, int lastAngle);
private: private:
const HarmonicAngleForce& owner; const HarmonicAngleForce& owner;
Kernel kernel; Kernel kernel;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
} }
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
std::vector<std::pair<int, int> > getBondedParticles() const; std::vector<std::pair<int, int> > getBondedParticles() const;
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstBond, int lastBond);
private: private:
const HarmonicBondForce& owner; const HarmonicBondForce& owner;
Kernel kernel; Kernel kernel;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2018 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstParticle, int lastParticle, int firstException, int lastException);
void getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const; void getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const;
void getLJPMEParameters(double& alpha, int& nx, int& ny, int& nz) const; void getLJPMEParameters(double& alpha, int& nx, int& ny, int& nz) const;
/** /**
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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 Stanford University and the Authors. * * Portions copyright (c) 2008-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context); void updateParametersInContext(ContextImpl& context, int firstTorsion, int lastTorsion);
private: private:
const PeriodicTorsionForce& owner; const PeriodicTorsionForce& owner;
Kernel kernel; Kernel kernel;
......
...@@ -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) 2010-2016 Stanford University and the Authors. * * Portions copyright (c) 2010-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -40,11 +40,9 @@ ...@@ -40,11 +40,9 @@
#include <utility> #include <utility>
using namespace OpenMM; using namespace OpenMM;
using std::string; using namespace std;
using std::stringstream;
using std::vector;
CustomAngleForce::CustomAngleForce(const string& energy) : energyExpression(energy), usePeriodic(false) { CustomAngleForce::CustomAngleForce(const string& energy) : energyExpression(energy), usePeriodic(false), numContexts(0) {
} }
const string& CustomAngleForce::getEnergyFunction() const { const string& CustomAngleForce::getEnergyFunction() const {
...@@ -128,14 +126,30 @@ void CustomAngleForce::setAngleParameters(int index, int particle1, int particle ...@@ -128,14 +126,30 @@ void CustomAngleForce::setAngleParameters(int index, int particle1, int particle
angles[index].particle1 = particle1; angles[index].particle1 = particle1;
angles[index].particle2 = particle2; angles[index].particle2 = particle2;
angles[index].particle3 = particle3; angles[index].particle3 = particle3;
if (numContexts > 0) {
firstChangedAngle = min(index, firstChangedAngle);
lastChangedAngle = max(index, lastChangedAngle);
}
} }
ForceImpl* CustomAngleForce::createImpl() const { ForceImpl* CustomAngleForce::createImpl() const {
if (numContexts == 0) {
// Begin tracking changes to angles.
firstChangedAngle = angles.size();
lastChangedAngle = -1;
}
numContexts++;
return new CustomAngleForceImpl(*this); return new CustomAngleForceImpl(*this);
} }
void CustomAngleForce::updateParametersInContext(Context& context) { void CustomAngleForce::updateParametersInContext(Context& context) {
dynamic_cast<CustomAngleForceImpl&>(getImplInContext(context)).updateParametersInContext(getContextImpl(context)); dynamic_cast<CustomAngleForceImpl&>(getImplInContext(context)).updateParametersInContext(getContextImpl(context), firstChangedAngle, lastChangedAngle);
if (numContexts == 1) {
// We just updated the only existing context for this force, so we can reset
// the tracking of changed angles.
firstChangedAngle = angles.size();
lastChangedAngle = -1;
}
} }
void CustomAngleForce::setUsesPeriodicBoundaryConditions(bool periodic) { void CustomAngleForce::setUsesPeriodicBoundaryConditions(bool periodic) {
......
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