Owns and coordinates native GPU force-evaluation backends. More...
#include <ForceManager.h>
Inherits std::enable_shared_from_this< ForceManager >.
Public Member Functions | |
| ForceManager (void) | |
| Constructs an uninitialized manager with default configuration. | |
| ForceManager (std::shared_ptr< CharmmPSF > psf, std::shared_ptr< CharmmParameters > prm) | |
| Constructs an uninitialized manager from a PSF and parameter set. | |
| ForceManager (const ForceManager &other) | |
| Constructs a configuration-only deep copy of another manager. | |
| virtual | ~ForceManager (void) noexcept |
| Destroys the manager and releases its owned native resources. | |
| void | setContext (std::shared_ptr< CharmmContext > ctx) |
Stores a non-owning association with a CharmmContext. | |
| void | setPsf (std::shared_ptr< CharmmPSF > psf) |
| Sets the PSF retained by the manager. | |
| void | setPrm (std::shared_ptr< CharmmParameters > prm) |
| Sets the parameter set retained by the manager. | |
| void | addPsf (const std::filesystem::path &psfPath) |
| Loads and installs a PSF from a file. | |
| void | addPrm (const std::filesystem::path &prmPath) |
| Loads and installs parameters from one file. | |
| void | addPrm (const std::vector< std::filesystem::path > &prmList) |
| Loads and installs parameters from an ordered list of files. | |
| virtual void | setBoxDimensions (const std::vector< double > &size) |
| Sets the orthorhombic box dimensions. | |
| virtual void | setKappa (const float kappa) |
| Sets the Ewald splitting parameter. | |
| virtual void | setCutoff (const float cutoff) |
| Sets the direct-space pair-list cutoff. | |
| virtual void | setCtonnb (const float ctonnb) |
Sets the outer nonbonded switching distance exposed as ctonnb. | |
| virtual void | setCtofnb (const float ctofnb) |
Sets the inner nonbonded switching distance exposed as ctofnb. | |
| virtual void | setFFTGrid (const int nfftx, const int nffty, const int nfftz) |
| Sets the three PME FFT grid dimensions. | |
| virtual void | setPmeSplineOrder (const int pmeSplineOrder) |
| Sets the PME interpolation spline order. | |
| virtual void | setPeriodicBoundaryCondition (const PBC pbc) |
| Sets the periodic boundary condition. | |
| virtual void | setVdwType (const int vdwType) |
| Sets the native van der Waals model code. | |
| void | setPrintEnergyDecomposition (const bool printEnergyDecomposition=true) |
| Enables or disables energy-decomposition printing. | |
| virtual void | addForceManager (std::shared_ptr< ForceManager > fm) |
| Rejects child managers in the non-composite base implementation. | |
| std::shared_ptr< CharmmContext > | getContext (void) |
Returns the associated CharmmContext when it is still alive. | |
| bool | hasCharmmContext (void) const |
Reports whether the associated CharmmContext is still alive. | |
| virtual std::shared_ptr< CharmmPSF > | getPsf (void) |
| Returns the retained PSF. | |
| std::shared_ptr< CharmmParameters > | getPrm (void) |
| Returns the retained parameter set. | |
| virtual bool | isInitialized (void) const |
| Reports whether native force initialization completed. | |
| const CudaContainer< int4 > & | getShakeAtoms (void) const |
| Returns read-only SHAKE atom-index records. | |
| CudaContainer< int4 > & | getShakeAtoms (void) |
| Returns mutable SHAKE atom-index records. | |
| const CudaContainer< float4 > & | getShakeParams (void) const |
| Returns read-only SHAKE parameter records. | |
| CudaContainer< float4 > & | getShakeParams (void) |
| Returns mutable SHAKE parameter records. | |
| const CudaEnergyVirial & | getBondedEnergyVirial (void) const |
| Returns read-only bonded energy and virial state. | |
| CudaEnergyVirial & | getBondedEnergyVirial (void) |
| Returns mutable bonded energy and virial state. | |
| const CudaEnergyVirial & | getReciprocalEnergyVirial (void) const |
| Returns read-only reciprocal energy and virial state. | |
| CudaEnergyVirial & | getReciprocalEnergyVirial (void) |
| Returns mutable reciprocal energy and virial state. | |
| const CudaEnergyVirial & | getDirectEnergyVirial (void) const |
| Returns read-only direct-space energy and virial state. | |
| CudaEnergyVirial & | getDirectEnergyVirial (void) |
| Returns mutable direct-space energy and virial state. | |
| std::map< std::string, double > | getEnergyComponents (void) |
| Returns the current host-side energy decomposition. | |
| std::shared_ptr< cudaStream_t > | getBondedStream (void) |
| Returns the bonded-force CUDA stream holder. | |
| std::shared_ptr< cudaStream_t > | getReciprocalStream (void) |
| Returns the reciprocal-force CUDA stream holder. | |
| std::shared_ptr< cudaStream_t > | getDirectStream (void) |
| Returns the direct-force CUDA stream holder. | |
| std::shared_ptr< cudaStream_t > | getForceManagerStream (void) |
| Returns the aggregate-force CUDA stream holder. | |
| std::shared_ptr< Force< long long int > > | getBondedForcevalues (void) |
| Returns synchronized bonded fixed-point force storage. | |
| std::shared_ptr< Force< long long int > > | getReciprocalForcevalues (void) |
| Returns synchronized reciprocal fixed-point force storage. | |
| std::shared_ptr< Force< long long int > > | getDirectForcevalues (void) |
| Returns synchronized direct-space fixed-point force storage. | |
| std::shared_ptr< Force< double > > | getTotalForcevalues (void) |
| Returns synchronized aggregate double-precision force storage. | |
| virtual std::shared_ptr< Force< double > > | getForces (void) |
| Returns the aggregate double-precision force storage. | |
| int | getForceStride (void) const |
| Returns the component stride of aggregate force storage. | |
| virtual const std::vector< double > & | getBoxDimensions (void) const |
| Returns read-only stored box dimensions. | |
| virtual std::vector< double > & | getBoxDimensions (void) |
| Returns mutable stored box dimensions. | |
| float | getKappa (void) const |
| Returns the stored Ewald splitting parameter. | |
| float | getCutoff (void) const |
| Returns the stored pair-list cutoff. | |
| float | getCtonnb (void) const |
Returns the stored outer switching distance exposed as ctonnb. | |
| float | getCtofnb (void) const |
Returns the stored inner switching distance exposed as ctofnb. | |
| std::vector< int > | getFFTGrid (void) const |
| Returns the three stored PME FFT grid dimensions. | |
| int | getPmeSplineOrder (void) const |
| Returns the PME interpolation spline order. | |
| PBC | getPeriodicBoundaryCondition (void) const |
| Returns the stored periodic boundary condition. | |
| virtual CudaContainer< double > & | getPotentialEnergy (void) |
| Returns aggregate potential-energy storage. | |
| virtual float | getPotentialEnergies (void) |
| Returns the current standard potential-energy sum on the host. | |
| virtual CudaContainer< double > & | getVirial (void) |
| Sums standard and eligible subscribed virial contributions. | |
| int | getVdwType (void) const |
| Returns the native van der Waals model code. | |
| virtual bool | isComposite (void) const |
| Reports whether this manager is composite. | |
| virtual const std::vector< std::shared_ptr< ForceManager > > & | getChildren (void) const |
| Returns read-only child-manager storage. | |
| virtual std::vector< std::shared_ptr< ForceManager > > & | getChildren (void) |
| Returns mutable child-manager storage. | |
| virtual void | initialize (void) |
| Initializes all native force-evaluation state. | |
| virtual void | resetNeighborList (const float4 *xyzq) |
| Rebuilds the direct-space neighbor list for current coordinates. | |
| void | calcForcePart1 (const bool reset, const bool calcEnergy, const bool calcVirial) |
| Clears force and requested energy-virial state. | |
| void | calcForcePart2 (const float4 *xyzq, const bool calcEnergy, const bool calcVirial) |
| Enqueues all built-in and subscribed force calculations. | |
| void | calcForcePart3 (const float4 *xyzq, const bool calcEnergy, const bool calcVirial) |
| Synchronizes component work and assembles aggregate outputs. | |
| virtual void | calcForce (const float4 *xyzq, const bool reset=false, const bool calcEnergy=false, const bool calcVirial=false) |
| Computes aggregate forces and optional energy and virial outputs. | |
| template<typename ForceType > | |
| void | subscribe (std::shared_ptr< ForceType > force, const std::string &forceTag, std::shared_ptr< cudaStream_t > forceStream, std::shared_ptr< Force< long long int > > forceValues, std::shared_ptr< CudaEnergyVirial > energyVirial) |
| Subscribes an additional force and its CUDA resources. | |
| template<typename ForceType > | |
| void | unsubscribe (std::shared_ptr< ForceType > force) |
| Unsubscribes a force by object identity. | |
| void | unsubscribe (const std::string &forceTag) |
| Unsubscribes the first force with a matching tag. | |
| virtual CudaContainer< double > | computeAllChildrenPotentialEnergy (const float4 *xyzq) |
| Rejects child-energy evaluation in the base manager. | |
Protected Member Functions | |
| void | initializeHolonomicConstraintsVariables (void) |
| Builds GPU SHAKE records from PSF bonds and parameter data. | |
| std::vector< int > | computeFFTGridSize (void) |
| Computes automatic even PME FFT grid dimensions. | |
| void | checkBoxDimensions (const std::vector< double > &boxDimensions) |
| Validates an orthorhombic box-dimension vector. | |
Owns and coordinates native GPU force-evaluation backends.
A ForceManager combines a CharmmPSF and CharmmParameters with box, Ewald, cutoff, FFT-grid, spline, periodic-boundary, and van der Waals configuration. Initialization constructs the bonded, direct-space, and reciprocal-space CUDA backends, creates their streams and force storage, initializes already subscribed forces, and allocates aggregate force, energy, virial, and holonomic-constraint state.
The manager retains shared ownership of its PSF and parameter set. Its association with a CharmmContext is weak and does not extend the context's lifetime. Subscribed force objects and their associated streams, force arrays, and energy-virial objects are retained through shared ownership until they are unsubscribed or the manager is destroyed.
Before initialization, callers must supply a PSF, a parameter set, and three positive box lengths. Configuration setters should normally be called before the first initialization. Several setters update stored configuration without rebuilding an already active backend.
Force calculations consume a device-resident float4 coordinate-charge array and produce device-resident structure-of-arrays force storage. Component calculations use separate CUDA streams and are synchronized before the aggregate force is returned as complete.
The base class is non-composite. Derived managers may override the child, initialization, force, and potential-energy extension points.
ForceManager provides no internal synchronization for concurrent host access. Configuration, subscription, initialization, force evaluation, and mutable accessor use must be externally serialized. isInitialized() remains false. | ForceManager::ForceManager | ( | void | ) |
Constructs an uninitialized manager with default configuration.
The manager initially has no PSF, no parameter set, no context, no CUDA force backends, and sentinel box dimensions. Its defaults are:
0.34 inverse angstroms;14.0 angstroms;ctonnb, 12.0 angstroms;ctofnb, 10.0 angstroms;-1 on each axis;4;VDW_VFSW; andFive nine-element virial work containers are allocated and initialized to zero during construction.
isInitialized() returns false. | ApoCharmmError | With code ApoCharmmErrorCode::Cuda if virial storage allocation or initialization fails in CUDA. |
| std::bad_alloc | If host-side object or container allocation fails. |
| ForceManager::ForceManager | ( | std::shared_ptr< CharmmPSF > | psf, |
| std::shared_ptr< CharmmParameters > | prm | ||
| ) |
Constructs an uninitialized manager from a PSF and parameter set.
The manager retains shared ownership of both collaborators; it does not copy either object. CUDA force backends are not created until initialize() is called directly or through a CharmmContext.
| [in] | psf | Shared owner of a non-null PSF. The manager retains a copy of the shared pointer. |
| [in] | prm | Shared owner of a non-null parameter set. The manager retains a copy of the shared pointer. |
getPsf() and getPrm() share ownership with the supplied objects. isInitialized() returns false. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if psf or prm is null. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if default virial storage construction fails. |
| std::bad_alloc | If host-side allocation fails. |
| ForceManager::ForceManager | ( | const ForceManager & | other | ) |
Constructs a configuration-only deep copy of another manager.
A non-null PSF and parameter set are copied into independent CharmmPSF and CharmmParameters objects. Box dimensions, Ewald and cutoff values, FFT dimensions, spline order, periodic-boundary condition, and van der Waals model are copied.
The context association, initialized state, CUDA streams, CUDA backends, force arrays, energy and virial values, subscribed forces, children, CUDA clear graph, and print-energy flag are not copied. They retain the default constructor state in the new manager.
| [in] | other | Manager whose configuration is copied. The source remains unchanged. |
other. | ApoCharmmError | With code ApoCharmmErrorCode::Cuda if default virial storage construction or a copied CUDA-backed collaborator fails. |
| std::bad_alloc | If collaborator or container allocation fails. |
|
virtualnoexcept |
Destroys the manager and releases its owned native resources.
CUDA streams and cached graph objects are destroyed through non-throwing cleanup paths. Cleanup failures are discarded. Shared ownership of the PSF, parameter set, subscribed-force resources, and force arrays is released.
A separately retained PSF, parameter set, subscribed force, or force-array shared pointer may outlive the manager. A shared pointer returned by a stream getter may keep the host cudaStream_t value allocated, but the manager still destroys the underlying CUDA stream, so that handle must not be used after manager destruction.
|
virtual |
Rejects child managers in the non-composite base implementation.
Derived composite managers override this extension point.
| [in] | fm | Proposed child manager. |
| ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if fm is null. |
| ApoCharmmError | With code ApoCharmmErrorCode::Runtime for every non-null fm, because the base manager does not support children. |
| void ForceManager::addPrm | ( | const std::filesystem::path & | prmPath | ) |
Loads and installs parameters from one file.
A new CharmmParameters is constructed from prmFile. The existing parameter set is replaced only after construction succeeds, then the initialized flag is cleared.
| [in] | prmPath | Non-empty file-system path to a CHARMM parameter or stream file. |
getPrm() owns the newly parsed parameter set and isInitialized() returns false. | ApoCharmmError | With code ApoCharmmErrorCode::Runtime if the file cannot be read or a parameter record is invalid. |
| std::bad_alloc | If parsing or collaborator allocation fails. |
| void ForceManager::addPrm | ( | const std::vector< std::filesystem::path > & | prmList | ) |
Loads and installs parameters from an ordered list of files.
Files are parsed in prmList order into one new CharmmParameters object. The existing parameter set is replaced only after all files are parsed successfully, then the initialized flag is cleared.
| [in] | prmList | Non-empty ordered list of file-system paths to CHARMM parameter or stream files. |
getPrm() owns the newly parsed parameter set and isInitialized() returns false. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if prmList is empty. |
| ApoCharmmError | With code ApoCharmmErrorCode::Runtime if a file cannot be read or a parameter record is invalid. |
| std::bad_alloc | If parsing or collaborator allocation fails. |
| void ForceManager::addPsf | ( | const std::filesystem::path & | psfPath | ) |
Loads and installs a PSF from a file.
A new CharmmPSF is constructed from psfFile. The existing PSF is replaced only after construction succeeds, then the initialized flag is cleared.
| [in] | psfPath | Non-empty file-system path to the CHARMM PSF file. |
getPsf() owns the newly parsed PSF and isInitialized() returns false. | ApoCharmmError | With code ApoCharmmErrorCode::Runtime if the file cannot be read or its PSF records are invalid. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if construction of CUDA-backed PSF data fails. |
| std::bad_alloc | If parsing or collaborator allocation fails. |
|
virtual |
Computes aggregate forces and optional energy and virial outputs.
This convenience method calls calcForcePart1(), calcForcePart2(), and calcForcePart3() in that order.
| [in] | xyzq | Borrowed device pointer to at least the retained PSF's atom float4 records in [x, y, z, charge] order. |
| [in] | reset | Must be false; true is currently unsupported. |
| [in] | calcEnergy | Whether to compute and aggregate potential energy. |
| [in] | calcVirial | Whether to compute virial contributions. |
xyzq is non-null, device-accessible, and remains valid through completion. | ApoCharmmError | With code ApoCharmmErrorCode::NotImplemented if reset is true. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if any CUDA operation in the three phases fails. |
| ApoCharmmError | Propagates categorized built-in or subscribed-force failures. |
reset is false. | void ForceManager::calcForcePart1 | ( | const bool | reset, |
| const bool | calcEnergy, | ||
| const bool | calcVirial | ||
| ) |
Clears force and requested energy-virial state.
On first use, the method captures and instantiates a CUDA graph that clears the three built-in fixed-point force arrays. Later calls launch the cached graph. Requested energy and virial state is cleared on the component streams, subscribed forces are cleared, and the aggregate stream is synchronized before return.
| [in] | reset | Must be false; neighbor-list reset through this argument is not implemented. |
| [in] | calcEnergy | Whether energy state will be computed and therefore must be cleared. |
| [in] | calcVirial | Whether virial state will be computed and therefore must be cleared. |
| ApoCharmmError | With code ApoCharmmErrorCode::NotImplemented if reset is true. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if graph capture, instantiation, launch, force clearing, or synchronization fails. |
| ApoCharmmError | Propagates a categorized subscribed-force clear failure. |
| void ForceManager::calcForcePart2 | ( | const float4 * | xyzq, |
| const bool | calcEnergy, | ||
| const bool | calcVirial | ||
| ) |
Enqueues all built-in and subscribed force calculations.
Bonded, reciprocal, and direct calculations are enqueued on their respective streams. Each subscribed force is then invoked, with its virial flag enabled only when both calcVirial is true and the force declares that it contributes a virial.
| [in] | xyzq | Borrowed device pointer to at least getNumAtoms() float4 coordinate-charge records. |
| [in] | calcEnergy | Whether each force should compute energy. |
| [in] | calcVirial | Whether eligible forces should compute virial. |
calcForcePart1() has completed for this evaluation. xyzq is valid device storage. | ApoCharmmError | Propagates categorized backend, subscribed-force, or CUDA failures. |
| void ForceManager::calcForcePart3 | ( | const float4 * | xyzq, |
| const bool | calcEnergy, | ||
| const bool | calcVirial | ||
| ) |
Synchronizes component work and assembles aggregate outputs.
The method clears aggregate force storage, waits for each component and subscribed stream, and adds every fixed-point force into the aggregate double-precision force array. When requested, it converts force storage for virial calculation, computes eligible virials, copies energies to host storage, sums standard and subscribed energy terms on the aggregate stream, and optionally prints the decomposition.
| [in] | xyzq | Borrowed device pointer to the same coordinate-charge array passed to calcForcePart2(). |
| [in] | calcEnergy | Whether to update aggregate potential-energy state. |
| [in] | calcVirial | Whether to update virial state. |
calcForcePart2() has enqueued all component calculations. xyzq remains valid. calcEnergy is true, aggregate device energy is complete and all component host energy mirrors have been copied. calcVirial is true, requested virial calculations have completed. | ApoCharmmError | With code ApoCharmmErrorCode::Cuda if synchronization, conversion, aggregation, transfer, or a CUDA launch reports failure. |
| ApoCharmmError | Propagates categorized subscribed-force failures. |
calcEnergy or calcVirial is false, the corresponding previous output remains observable and must be treated as stale.
|
protected |
Validates an orthorhombic box-dimension vector.
| [in] | boxDimensions | Vector that must contain exactly three finite positive values in angstroms. |
| ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if the length is not three or any value is non-finite or not positive. |
|
virtual |
Rejects child-energy evaluation in the base manager.
Derived composite managers override this extension point.
| [in] | xyzq | Proposed device coordinate-charge array. |
| ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if xyzq is null. |
| ApoCharmmError | With code ApoCharmmErrorCode::Runtime for every non-null xyzq, because the base manager does not support child evaluation. |
|
protected |
Computes automatic even PME FFT grid dimensions.
Each result is the largest even integer not greater than the corresponding box length after truncation to int, with a minimum value of 2. A warning is written to std::cout when a minimum is applied.
{nfftx, nffty, nfftz} vector of dimensionless grid sizes. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if the stored box vector is not exactly three finite positive values. |
| std::bad_alloc | If return-vector allocation fails. |
| CudaEnergyVirial & ForceManager::getBondedEnergyVirial | ( | void | ) |
Returns mutable bonded energy and virial state.
| const CudaEnergyVirial & ForceManager::getBondedEnergyVirial | ( | void | ) | const |
Returns read-only bonded energy and virial state.
| std::shared_ptr< Force< long long int > > ForceManager::getBondedForcevalues | ( | void | ) |
Returns synchronized bonded fixed-point force storage.
Force<long long int> storage. Components use structure-of-arrays layout with X at offset 0, Y at stride, and Z at 2 * stride. Raw values must be multiplied by INV_FORCE_SCALE to recover force values in kilocalories per mole per angstrom.| ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if synchronizing the aggregate stream fails. |
| std::shared_ptr< cudaStream_t > ForceManager::getBondedStream | ( | void | ) |
Returns the bonded-force CUDA stream holder.
cudaStream_t value, or an empty pointer before initialization.
|
virtual |
Returns mutable stored box dimensions.
setBoxDimensions().
|
virtual |
Returns read-only stored box dimensions.
[x, y, z] order, in angstroms. Before a box is set, the base constructor stores three sentinel values near -9999.9999.
|
virtual |
Returns mutable child-manager storage.
addForceManager() and can make isComposite() disagree with the stored children.
|
virtual |
Returns read-only child-manager storage.
| std::shared_ptr< CharmmContext > ForceManager::getContext | ( | void | ) |
Returns the associated CharmmContext when it is still alive.
std::shared_ptr when the weak association is unset or expired. | float ForceManager::getCtofnb | ( | void | ) | const |
Returns the stored inner switching distance exposed as ctofnb.
| float ForceManager::getCtonnb | ( | void | ) | const |
Returns the stored outer switching distance exposed as ctonnb.
| float ForceManager::getCutoff | ( | void | ) | const |
Returns the stored pair-list cutoff.
| CudaEnergyVirial & ForceManager::getDirectEnergyVirial | ( | void | ) |
Returns mutable direct-space energy and virial state.
| const CudaEnergyVirial & ForceManager::getDirectEnergyVirial | ( | void | ) | const |
Returns read-only direct-space energy and virial state.
| std::shared_ptr< Force< long long int > > ForceManager::getDirectForcevalues | ( | void | ) |
Returns synchronized direct-space fixed-point force storage.
getBondedForcevalues(). | ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if synchronization fails. |
| std::shared_ptr< cudaStream_t > ForceManager::getDirectStream | ( | void | ) |
Returns the direct-force CUDA stream holder.
cudaStream_t value, or an empty pointer before initialization.| std::map< std::string, double > ForceManager::getEnergyComponents | ( | void | ) |
Returns the current host-side energy decomposition.
The returned map contains the keys bond, angle, ureyb, dihe, imdihe, cmap, ewks, ewse, ewex, elec, vdw, and user. user is the sum of the default energy component from every subscribed energy-virial object. Values use kilocalories per mole.
This method reads existing host mirrors. It does not copy energy values from the device and does not synchronize a CUDA stream.
| ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| std::bad_alloc | If map or string allocation fails. |
| std::vector< int > ForceManager::getFFTGrid | ( | void | ) | const |
Returns the three stored PME FFT grid dimensions.
{nfftx, nffty, nfftz} vector of dimensionless grid sizes. Before an explicit grid or successful initialization, each value is -1. | std::shared_ptr< cudaStream_t > ForceManager::getForceManagerStream | ( | void | ) |
Returns the aggregate-force CUDA stream holder.
cudaStream_t value, or an empty pointer before initialization.
|
virtual |
Returns the aggregate double-precision force storage.
This is an aliasing API for getTotalForcevalues().
Force<double> object returned by getTotalForcevalues(). | ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if synchronization fails. |
| int ForceManager::getForceStride | ( | void | ) | const |
Returns the component stride of aggregate force storage.
double elements between corresponding X, Y, and Z components. The value is dimensionless and may exceed the atom count due to alignment. | ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| float ForceManager::getKappa | ( | void | ) | const |
Returns the stored Ewald splitting parameter.
| PBC ForceManager::getPeriodicBoundaryCondition | ( | void | ) | const |
Returns the stored periodic boundary condition.
| int ForceManager::getPmeSplineOrder | ( | void | ) | const |
Returns the PME interpolation spline order.
4.
|
virtual |
Returns the current standard potential-energy sum on the host.
The current implementation copies the bonded, reciprocal, and direct energy-virial objects to host storage, synchronizes the aggregate stream, and sums bond, angle, ureyb, dihe, imdihe, ewks, ewse, ewex, elec, and vdw.
float, in kilocalories per mole. | ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if a device-to-host copy or stream synchronization fails. |
cmap term and all subscribed-force energies. It is therefore not equivalent to the one-element total produced by calcForce(..., calcEnergy = true, ...).
|
virtual |
Returns aggregate potential-energy storage.
CudaContainer<double> in kilocalories per mole.| ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
calcForce() is called with calcEnergy == true. The host mirror is transferred only by code that explicitly requests a transfer or prints the decomposition. | std::shared_ptr< CharmmParameters > ForceManager::getPrm | ( | void | ) |
Returns the retained parameter set.
|
virtual |
Returns the retained PSF.
| CudaEnergyVirial & ForceManager::getReciprocalEnergyVirial | ( | void | ) |
Returns mutable reciprocal energy and virial state.
| const CudaEnergyVirial & ForceManager::getReciprocalEnergyVirial | ( | void | ) | const |
Returns read-only reciprocal energy and virial state.
| std::shared_ptr< Force< long long int > > ForceManager::getReciprocalForcevalues | ( | void | ) |
Returns synchronized reciprocal fixed-point force storage.
getBondedForcevalues(). | ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if synchronization fails. |
| std::shared_ptr< cudaStream_t > ForceManager::getReciprocalStream | ( | void | ) |
Returns the reciprocal-force CUDA stream holder.
cudaStream_t value, or an empty pointer before initialization.| CudaContainer< int4 > & ForceManager::getShakeAtoms | ( | void | ) |
Returns mutable SHAKE atom-index records.
| const CudaContainer< int4 > & ForceManager::getShakeAtoms | ( | void | ) | const |
Returns read-only SHAKE atom-index records.
Each int4 record represents one heavy-atom-centered constrained group: (heavy, hydrogen1, hydrogen2, hydrogen3). Unused hydrogen positions are -1. The container is populated by initialize() and may be empty.
| CudaContainer< float4 > & ForceManager::getShakeParams | ( | void | ) |
Returns mutable SHAKE parameter records.
| const CudaContainer< float4 > & ForceManager::getShakeParams | ( | void | ) | const |
Returns read-only SHAKE parameter records.
Each float4 contains the solver fields (inverse-heavy-mass, average-mass-field, squared-bond-length, inverse-hydrogen-mass). Reciprocal masses use inverse atomic mass units, the average-mass field uses atomic mass units, and the squared bond length uses square angstroms. The representation is solver-internal and is not a stable interchange format.
| std::shared_ptr< Force< double > > ForceManager::getTotalForcevalues | ( | void | ) |
Returns synchronized aggregate double-precision force storage.
Force<double> storage using structure-of-arrays layout and force units of kilocalories per mole per angstrom. | ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if synchronization fails. |
| int ForceManager::getVdwType | ( | void | ) | const |
Returns the native van der Waals model code.
[1, 6] for manager state created through the validated setter.
|
virtual |
Sums standard and eligible subscribed virial contributions.
The method obtains the bonded, reciprocal, and direct nine-element virial arrays, transfers them to the host, halves the reciprocal contribution for PBC::P21, adds subscribed virials whose force type reports contributesVirial, and transfers the aggregate back to the device.
CudaContainer<double>. Values use energy units of kilocalories per mole. Both host and device representations contain the aggregate on successful return. | ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the manager is not initialized. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if a virial copy or transfer fails. |
| bool ForceManager::hasCharmmContext | ( | void | ) | const |
Reports whether the associated CharmmContext is still alive.
true when the stored weak reference is not expired; otherwise false.ForceManager provides no internal locking.
|
virtual |
Initializes all native force-evaluation state.
Initialization validates required collaborators and configuration, selects an automatic FFT grid when any stored FFT dimension is not positive, and constructs resources in this order:
subscribe();The method performs a device-wide synchronization before creating the aggregate potential-energy container and marks the manager initialized only after every phase succeeds.
isInitialized() returns true; all four native streams and force arrays are allocated; and already subscribed forces have received the atom count and box. | ApoCharmmError | With code ApoCharmmErrorCode::NotInitialized if the PSF, parameter set, or box has not been set. |
| ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if the cutoff is invalid for the X box length or automatic-grid validation fails. |
| ApoCharmmError | With code ApoCharmmErrorCode::Runtime if the PSF atom count is not positive or a topology/parameter operation reports a runtime failure. |
| ApoCharmmError | With code ApoCharmmErrorCode::Cuda if CUDA stream creation, force allocation, backend setup, transfer, or synchronization fails. |
| std::bad_alloc | If native object or container allocation fails. |
isInitialized() remains false.
|
protected |
Builds GPU SHAKE records from PSF bonds and parameter data.
Hydrogen-containing bonds are grouped by heavy atom, except the currently excluded OT-HT and hydrogen-hydrogen cases. Each selected group creates one int4 atom record and one float4 parameter record as documented by the public SHAKE accessors. The generated vectors are assigned to m_ShakeAtoms and m_ShakeParams, which copies their contents into the corresponding CUDA containers.
m_Psf and m_Prm are non-null and describe compatible atom, topology, mass, atom-type, and bond-parameter data. | ApoCharmmError | Propagates categorized PSF, parameter, container, or CUDA failures. |
| std::bad_alloc | If grouping or record allocation fails. |
|
virtual |
Reports whether this manager is composite.
false for the base ForceManager.
|
virtual |
Reports whether native force initialization completed.
true only after initialize() reaches its successful final assignment; otherwise false.false result does not imply that no partial CUDA resources were allocated by an earlier failed initialization.
|
virtual |
Rebuilds the direct-space neighbor list for current coordinates.
| [in] | xyzq | Borrowed device pointer to at least the retained PSF's atom float4 records in [x, y, z, charge] order. Coordinates are in angstroms and charges are in elementary-charge units. |
xyzq is non-null, device-accessible, and remains valid until the direct backend has completed its work. | ApoCharmmError | Propagates a categorized direct-backend or CUDA failure. |
|
virtual |
Sets the orthorhombic box dimensions.
The three values are copied into the manager's double-precision box vector and narrowed to the float scalar fields used by the native force backends. Existing bonded, reciprocal, direct, and subscribed force objects receive the new box in that order.
This call does not recompute an automatic FFT grid, reset the direct-space neighbor list, or clear the initialized flag.
| [in] | size | Exactly three finite positive lengths in [x, y, z] order, in angstroms. |
getBoxDimensions() equals size. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if size does not contain exactly three values, or if any value is non-finite or not positive. |
| ApoCharmmError | Propagates a categorized error from an already constructed native or subscribed force receiving the box update. |
| void ForceManager::setContext | ( | std::shared_ptr< CharmmContext > | ctx | ) |
Stores a non-owning association with a CharmmContext.
The manager stores ctx as a std::weak_ptr. Passing nullptr clears the association. This method does not modify the supplied context and does not call CharmmContext::setForceManager().
| [in] | ctx | Context whose control block is observed. The pointer may be null and is not retained through shared ownership. |
getContext() returns a shared owner when the context is still alive, or an empty pointer after the association is cleared or expires.
|
virtual |
Sets the inner nonbonded switching distance exposed as ctofnb.
The current backend forwarding uses this value as the distance at which switching begins.
| [in] | ctofnb | Finite positive distance in angstroms. |
getCtofnb() returns ctofnb. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if ctofnb is non-finite or not positive. |
ctonnb and ctofnb.
|
virtual |
Sets the outer nonbonded switching distance exposed as ctonnb.
The current backend forwarding uses this value as the distance at which the switching function reaches zero.
| [in] | ctonnb | Finite positive distance in angstroms. |
getCtonnb() returns ctonnb. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if ctonnb is non-finite or not positive. |
ctonnb and ctofnb.
|
virtual |
Sets the direct-space pair-list cutoff.
| [in] | cutoff | Finite positive distance in angstroms. |
getCutoff() returns cutoff. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if cutoff is non-finite or not positive. |
initialize() additionally requires this value not to exceed half the X box length.
|
virtual |
Sets the three PME FFT grid dimensions.
| [in] | nfftx | Positive dimensionless grid size along X. |
| [in] | nffty | Positive dimensionless grid size along Y. |
| [in] | nfftz | Positive dimensionless grid size along Z. |
getFFTGrid() returns {nfftx, nffty, nfftz}. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if any dimension is not positive. |
|
virtual |
Sets the Ewald splitting parameter.
| [in] | kappa | Finite non-negative Ewald parameter in inverse angstroms. |
getKappa() returns kappa, subject to float representation. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if kappa is non-finite or negative. |
|
virtual |
Sets the periodic boundary condition.
| [in] | pbc | Declared PBC value to retain. |
getPeriodicBoundaryCondition() returns pbc. isInitialized() returns false.PBC.
|
virtual |
Sets the PME interpolation spline order.
| [in] | pmeSplineOrder | Positive dimensionless spline order. |
getPmeSplineOrder() returns pmeSplineOrder. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if pmeSplineOrder is not positive. |
| void ForceManager::setPrintEnergyDecomposition | ( | const bool | printEnergyDecomposition = true | ) |
Enables or disables energy-decomposition printing.
When enabled, calcForce() writes standard and subscribed energy components to std::cout whenever calcEnergy is true.
| [in] | printEnergyDecomposition | Whether to print energy terms. Omitting the argument enables printing. |
| void ForceManager::setPrm | ( | std::shared_ptr< CharmmParameters > | prm | ) |
Sets the parameter set retained by the manager.
The supplied object is retained through shared ownership and the manager's initialized flag is cleared. Existing CUDA streams, backends, cached graph state, and force arrays are not deallocated or rebuilt by this call.
| [in] | prm | Shared owner of a non-null parameter set. |
getPrm() shares ownership with prm. isInitialized() returns false. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if prm is null. The existing parameter set and initialized flag remain unchanged on this validation failure. |
| void ForceManager::setPsf | ( | std::shared_ptr< CharmmPSF > | psf | ) |
Sets the PSF retained by the manager.
The supplied object is retained through shared ownership and the manager's initialized flag is cleared. Existing CUDA streams, backends, cached graph state, and force arrays are not deallocated or rebuilt by this call.
| [in] | psf | Shared owner of a non-null PSF. |
getPsf() shares ownership with psf. isInitialized() returns false. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if psf is null. The existing PSF and initialized flag remain unchanged on this validation failure. |
|
virtual |
Sets the native van der Waals model code.
| [in] | vdwType | Integer model code from VDW_VSH through VDW_DBEXP, inclusive, corresponding to values 1 through 6. |
getVdwType() returns vdwType. | ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if vdwType is outside [1, 6]. |
|
inline |
Subscribes an additional force and its CUDA resources.
The manager retains shared ownership of force, forceStream, forceValues, and energyVirial. A type-erased ForceView is stored at the same index as those resources and forceTag. Successful operation therefore preserves the invariant that all six subscription vectors have equal length and corresponding indices describe one force.
If the manager is already initialized, force->initialize() is called with the current PSF atom count and box before any manager subscription vector is modified.
| ForceType | Concrete force type satisfying the ForceView interface. |
| [in] | force | Shared owner of the non-null force. The exact object address must not already be subscribed. |
| [in] | forceTag | Non-empty diagnostic and energy-print label. Tags are not required to be unique. |
| [in] | forceStream | Shared owner of the non-null CUDA stream holder used by this force. |
| [in] | forceValues | Shared owner of non-null fixed-point device force storage corresponding to force. |
| [in] | energyVirial | Shared owner of non-null energy and virial storage corresponding to force. |
| ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if any shared pointer is null, forceTag is empty, or the same force object is already subscribed. |
| ApoCharmmError | Propagates a categorized error from ForceType::initialize() when the manager is already initialized. |
| std::bad_alloc | If subscription-vector growth fails. |
force; the manager does not verify this relationship. push_back() operations can leave the parallel subscription vectors with different lengths.
|
inline |
Unsubscribes the first force with a matching tag.
Tags are not required to be unique. When multiple subscriptions use the same tag, only the lowest-index match is removed.
| [in] | forceTag | Non-empty tag to find. |
| ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if forceTag is empty or no subscription has that tag. |
|
inline |
Unsubscribes a force by object identity.
The first subscription whose retained object address equals force.get() is removed from every parallel subscription vector. The manager releases its shared references but does not clear or deinitialize the force.
| ForceType | Concrete force type previously passed to subscribe(). |
| [in] | force | Shared owner identifying the subscribed object. |
| ApoCharmmError | With code ApoCharmmErrorCode::InvalidArgument if force is null or its object address is not subscribed. |
|
protected |
Built-in energy and virial registries. Their device values are written on separate component streams, while host values are updated only by explicit copies.
|
protected |
Whether the bonded-force backend must be reconstructed before use.
|
protected |
Manager-owned built-in CUDA backend objects. They are null before initialization and are replaced by initialize().
|
protected |
Device-resident fixed-point force arrays for the three built-in force components. Each uses X/Y/Z structure-of-arrays layout and Force<long long int> scaling.
|
protected |
Host allocations containing the bonded, reciprocal, and direct CUDA stream handles. ForceManager owns and explicitly destroys the underlying CUDA streams.
|
protected |
Nine-element virial work arrays for built-in, subscribed, and aggregate contributions. The arrays maintain host and device storage.
|
protected |
Double-precision [x, y, z] orthorhombic box lengths in angstroms.
|
protected |
Float box lengths passed to selected native backends, in angstroms. They duplicate m_BoxDimensions and are updated only by setBoxDimensions().
|
protected |
Child-manager storage used by derived composite implementations. The base manager leaves it empty and reports isComposite() == false.
|
protected |
Cached CUDA graph used to clear the three built-in fixed-point force arrays. m_ClearGraphCreated is the lifecycle discriminator for the graph and executable handles.
|
protected |
Legacy direct-space computation-selection flag used by specialized manager implementations. The base constructor initializes it to true.
|
protected |
Non-owning backlink to the associated context. The context is never kept alive solely by its force manager.
|
protected |
Inner switching distance in angstroms as currently forwarded to the direct backend; default 10.0.
|
protected |
Outer switching distance in angstroms as currently forwarded to the direct backend; default 12.0.
|
protected |
Direct-space pair-list cutoff in angstroms, corresponding to CHARMM CUTNB; default 14.0.
|
protected |
Whether the direct-space backend must be reconstructed before use.
|
protected |
Host allocation containing the CUDA stream used for force clearing, aggregation, and total-energy kernels.
|
protected |
Parallel subscription state. For every valid index:
m_ForcePtrs owns the concrete force;m_ForceViews dispatches to that force;m_ForceTags stores its label;m_ForceStreams owns its stream holder;m_ForceValues owns its fixed-point force storage; andm_EnergyVirials owns its energy and virial storage.Successful subscription and unsubscription require all vectors to have equal length.
|
protected |
Successful-initialization flag. It changes to true only at the final statement of initialize() and can be cleared by selected collaborator or PBC setters without deallocating existing resources.
|
protected |
Ewald splitting parameter in inverse angstroms; default 0.34.
|
protected |
Dimensionless PME FFT dimensions. The -1 constructor sentinel selects automatic grid generation during initialization.
|
protected |
Positive dimensionless PME interpolation spline order; default 4.
|
protected |
Selects standard and subscribed energy output to std::cout during an energy-producing force calculation.
|
protected |
Shared owner of the force-field parameter set used by initialization.
|
protected |
Shared owner of the topology and atom metadata used by initialization.
|
protected |
Whether the reciprocal-space backend must be reconstructed before use.
|
protected |
Host/device mirrored SHAKE atom groups. Each int4 stores one heavy atom and up to three hydrogen atom indices.
|
protected |
Host/device mirrored solver parameters corresponding one-to-one with m_ShakeAtoms.
|
protected |
Device-resident double-precision aggregate force array. The exact force-versus-energy-gradient sign convention requires separate clarification; the current integration paths consume this object as the manager's force output.
|
protected |
One-element aggregate potential-energy storage in kilocalories per mole.
|
protected |
Native van der Waals model code; default VDW_VFSW.