Commit 0e879806 authored by Peter Eastman's avatar Peter Eastman
Browse files

Reorganization of the OpenMM source code

parent 949599de
#ifndef OPENMM_KERNEL_H_
#define OPENMM_KERNEL_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "KernelImpl.h"
namespace OpenMM {
/**
* A Kernel encapsulates a particular implementation of a calculation that can be performed on Streams.
* Kernel objects are created by Platforms:
*
* <pre>
* Kernel kernel = platform.createKernel(kernelName);
* </pre>
*
* The Kernel class itself does not specify any details of what calculation is to be performed or the API
* for calling it. Instead, subclasses of KernelImpl will define APIs which are appropriate to particular
* calculations. To execute a Kernel, you therefore requests its implementation object and cast it to the
* correct type:
*
* <pre>
* dynamic_cast<AddStreamsImpl&>(kernel.getImpl()).execute(stream1, stream2);
* </pre>
*/
class Kernel {
public:
Kernel();
Kernel(const Kernel& copy);
~Kernel();
Kernel operator=(const Kernel& copy);
/**
* Get the name of this Kernel.
*/
std::string getName() const;
/**
* Get the object which implements this Kernel.
*/
KernelImpl& getImpl();
private:
friend class Platform;
/**
* Create a KernelImpl.
*
* @param name the name of the kernel to create
*/
Kernel(KernelImpl* impl);
KernelImpl* impl;
};
} // namespace OpenMM
#endif /*OPENMM_KERNEL_H_*/
#ifndef OPENMM_KERNELFACTORY_H_
#define OPENMM_KERNELFACTORY_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "KernelImpl.h"
namespace OpenMM {
/**
* A KernelFactory is an object that can create KernelImpls. This is an abstract class.
* Each Platform maintains a list of KernelFactory objects that it uses to create
* KernelImpls as needed.
*/
class KernelFactory {
public:
/**
* Create a KernelImpl.
*
* @param name the name of the kernel to create
*/
virtual KernelImpl* createKernelImpl(std::string name) const = 0;
virtual ~KernelFactory() {
}
};
} // namespace OpenMM
#endif /*OPENMM_KERNELFACTORY_H_*/
#ifndef OPENMM_KERNELIMPL_H_
#define OPENMM_KERNELIMPL_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include <string>
namespace OpenMM {
/**
* A KernelImpl defines the internal implementation of a Kernel object. A subclass will typically
* declare an abstract execute() method which defines the API for executing the kernel. Other classes
* will in turn subclass it and provide concrete implementations of the execute() method.
*/
class KernelImpl {
public:
/**
* Create a KernelImpl.
*
* @param name the name of the kernel to create
*/
KernelImpl(std::string name);
virtual ~KernelImpl() {
}
/**
* Get the name of this kernel.
*/
std::string getName() const;
private:
friend class Kernel;
std::string name;
int referenceCount;
};
} // namespace OpenMM
#endif /*OPENMM_KERNELIMPL_H_*/
#ifndef OPENMM_PLATFORM_H_
#define OPENMM_PLATFORM_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "Stream.h"
#include <map>
#include <vector>
namespace OpenMM {
class Kernel;
class KernelFactory;
class StreamFactory;
/**
* A Platform defines an implementation of all the kernels and streams needed to perform some calculation.
* More precisely, a Platform object acts as a registry for a set of KernelFactory and StreamFactory
* objects which together implement the kernels and streams. The Platform class, in turn, provides a
* static registry of all available Platform objects.
*
* To get a Platform object, call
*
* <pre>
* Platform& platform Platform::findPlatform(kernelNames);
* </pre>
*
* passing in the names of all kernels that will be required for the calculation you plan to perform. It
* will return the fastest available Platform which provides implementations of all the specified kernels.
* You can then call createKernel() and createStream() to construct particular kernels and streams as needed.
*/
class Platform {
public:
virtual ~Platform() {
}
/**
* Get the name of this platform. This should be a unique identifier which can be used to recognized it.
*/
virtual std::string getName() const = 0;
/**
* Get an estimate of how fast this Platform class is. This need not be precise. It only is expected to
* return an order or magnitude estimate of the relative performance of different Platform classes. An
* unoptimized reference implementation should return 1.0, and all other Platforms should return a larger
* value that is an estimate of how many times faster they are than the reference implementation.
*/
virtual double getSpeed() const = 0;
/**
* Get whether this Platform supports double precision arithmetic. If this returns false, the platform
* is permitted to implement double precision streams internally as single precision.
*/
virtual bool supportsDoublePrecision() const = 0;
/**
* Get the default StreamFactory for this Platform. It will be used to create Streams whenever a
* different StreamFactory has not been registered for the requested stream name.
*/
virtual StreamFactory& getDefaultStreamFactory() const = 0;
/**
* Register a KernelFactory which should be used to create Kernels with a particular name.
*
* @param name the kernel name for which the factory should be used
* @param factory the factory to use for creating Kernels with the specified name
*/
void registerKernelFactory(std::string name, KernelFactory* factory);
/**
* Register a StreamFactory which should be used to create Streams with a particular name.
*
* @param name the stream name for which the factory should be used
* @param factory the factory to use for creating Streams with the specified name
*/
void registerStreamFactory(std::string name, StreamFactory* factory);
/**
* Determine whether this Platforms provides implementations of a set of kernels.
*
* @param kernelNames the names of the kernels of interests
* @return true if this Platform provides implementations of all the kernels in the list,
* false if there are any which it does not support
*/
bool supportsKernels(std::vector<std::string> kernelNames) const ;
/**
* Create a Kernel object. If you call this method multiple times with the same name,
* the returned Kernels are independent and do not interact with each other. This means
* that it is possible to have multiple simulations in progress at one time without them
* interfering.
*
* If no KernelFactory has been registered for the specified name, this will throw an exception.
*
* @param the name of the Kernel to get
* @return a newly created Kernel object
*/
Kernel createKernel(std::string name) const;
/**
* Create a Stream object. If you call this method multiple times with the same name,
* the returned Streams are independent and do not interact with each other. This means
* that it is possible to have multiple simulations in progress at one time without them
* interfering.
*
* If a StreamFactory has been registered for the specified name, it will be used to create
* the Stream. Otherwise, the default StreamFactory will be used.
*
* @param the name of the Stream to get
* @return a newly created Stream object
*/
Stream createStream(std::string name, int size, Stream::DataType type) const;
/**
* Register a new Platform.
*/
static void registerPlatform(Platform* platform);
/**
* Get the number of Platforms that have been registered.
*/
static int getNumPlatforms();
/**
* Get a registered Platform by index.
*/
static Platform& getPlatform(int index);
/**
* Find a Platform which can be used to perform a calculation.
*
* @param kernelNames the names of all kernels which will be needed for the calculation
* @return the fastest registered Platform which supports all of the requested kernels. If no
* Platform exists which supports all of them, this will throw an exception.
*/
static Platform& findPlatform(std::vector<std::string> kernelNames);
private:
std::map<std::string, KernelFactory*> kernelFactories;
std::map<std::string, StreamFactory*> streamFactories;
static std::vector<Platform*> platforms;
};
} // namespace OpenMM
#endif /*OPENMM_PLATFORM_H_*/
#ifndef OPENMM_PLATFORMEXCEPTION_H_
#define OPENMM_PLATFORMEXCEPTION_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include <exception>
#include <string>
namespace OpenMM {
/**
* This class represents an exception thrown by a platform implementation.
*/
class PlatformException : public std::exception {
public:
PlatformException(std::string message) : message(message) {
}
~PlatformException() throw() {
}
const char* what() const throw() {
return message.c_str();
}
private:
std::string message;
};
} // namespace OpenMM
#endif /*OPENMM_PLATFORMEXCEPTION_H_*/
#ifndef OPENMM_STREAM_H_
#define OPENMM_STREAM_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include <string>
namespace OpenMM {
class StreamImpl;
/**
* A Stream encapsulates a particular implementation of a stream of data elements. A Stream has three
* fundamental properties:
*
* <ul>
* <li>A name. Although a Stream's name has no impact on the API for working with it, a particular platform
* may choose to implement different Streams in different ways. The name allows it to distinguish them.</li>
* <li>A size. This is the number of data elements contained in the stream.</li>
* <li>A data type. There are three basic data types: 32 bit floating point (Float), 64 bit floating point
* (Double), and 32 bit signed integers (Integer). In addition, there are compound data types which allow
* a single stream element to contain multiple values. For example, the data type Float3 indicates that
* each stream element is an array of three 32 bit floats.</li>
* </ul>
* Stream objects are created by Platforms:
*
* <pre>
* Stream stream = platform.createStream(streamName, size, dataType);
* </pre>
*
* A Stream is an opaque reference to the stream data. You cannot access stream elements directly. Instead,
* you must query or modify the stream data by calling methods such as loadFromArray() and saveToArray().
* These are potentially expensive operations, since they may involve transferring data between main memory
* and video memory, so they should be called sparing.
*
* It is important to remember that the data type dictates only the API for working with the Stream, not how
* it is represented internally. For example, even if a Stream object has type Double, a particular Platform
* may choose to implement it internally with single precision values.
*/
class Stream {
public:
Stream();
Stream(const Stream& copy);
~Stream();
Stream operator=(const Stream& copy);
/**
* This is an enumeration of the allowed data types for a Stream.
*/
enum DataType {Float, Float2, Float3, Float4, Double, Double2, Double3, Double4, Integer, Integer2, Integer3, Integer4};
/**
* Get the name of this Stream.
*/
std::string getName() const;
/**
* Get the number of elements in this stream.
*/
int getSize() const;
/**
* Get the data type of each element in the stream.
*/
Stream::DataType getDataType() const;
/**
* Copy the contents of an array into this stream.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
void loadFromArray(const void* array);
/**
* Copy the contents of this stream into an array.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
void saveToArray(void* array);
/**
* Set every element of this stream to the same value.
*
* @param a pointer to the value. It is assumed to be of the correct data type for this stream.
*/
void fillWithValue(void* value);
/**
* Get the object which implements this Stream.
*/
StreamImpl& getImpl();
private:
friend class Platform;
/**
* Create a StreamImpl.
*
* @param name the name of the stream to create
*/
Stream(StreamImpl* impl);
StreamImpl* impl;
};
} // namespace OpenMM
#endif /*OPENMM_STREAM_H_*/
#ifndef OPENMM_STREAMFACTORY_H_
#define OPENMM_STREAMFACTORY_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "StreamImpl.h"
namespace OpenMM {
/**
* A StreamFactory is an object that can create StreamImpls. This is an abstract class.
* Each Platform maintains a list of StreamFactory objects that it uses to create
* StreamImpls as needed.
*/
class StreamFactory {
public:
/**
* Create a StreamImpl.
*
* @param name the name of the stream to create
* @param size the number of elements in the stream
* @param type the data type of each element in the stream
*/
virtual StreamImpl* createStreamImpl(std::string name, int size, Stream::DataType type) const = 0;
virtual ~StreamFactory() {
}
};
} // namespace OpenMM
#endif /*OPENMM_STREAMFACTORY_H_*/
#ifndef OPENMM_STREAMIMPL_H_
#define OPENMM_STREAMIMPL_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "Stream.h"
#include <string>
namespace OpenMM {
/**
* A StreamImpl defines the internal implementation of a Stream object.
*/
class StreamImpl {
public:
/**
* Create a StreamImpl.
*
* @param name the name of the stream to create
* @param size the number of elements in the stream
* @param type the data type of each element in the stream
*/
StreamImpl(std::string name, int size, Stream::DataType type);
virtual ~StreamImpl() {
}
/**
* Get the name of this stream.
*/
std::string getName() const;
/**
* Get the number of elements in this stream.
*/
int getSize() const;
/**
* Get the data type of each element in the stream.
*/
Stream::DataType getDataType() const;
/**
* Copy the contents of an array into this stream.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
virtual void loadFromArray(const void* array) = 0;
/**
* Copy the contents of this stream into an array.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
virtual void saveToArray(void* array) = 0;
/**
* Set every element of this stream to the same value.
*
* @param a pointer to the value. It is assumed to be of the correct data type for this stream.
*/
virtual void fillWithValue(void* value) = 0;
private:
friend class Stream;
std::string name;
int size;
Stream::DataType type;
int referenceCount;
};
} // namespace OpenMM
#endif /*OPENMM_STREAMIMPL_H_*/
#ifndef OPENMM_KERNELS_H_
#define OPENMM_KERNELS_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "KernelImpl.h"
#include "Stream.h"
#include <set>
#include <string>
#include <vector>
namespace OpenMM {
/**
* This kernel is invoked by StandardMMForceField to calculate the forces acting on the system.
*/
class CalcStandardMMForcesKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcStandardMMForces";
}
CalcStandardMMForcesKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bondIndices the two atoms connected by each bond term
* @param bondParameters the force parameters (length, k) for each bond term
* @param angleIndices the three atoms connected by each angle term
* @param angleParameters the force parameters (angle, k) for each angle term
* @param periodicTorsionIndices the four atoms connected by each periodic torsion term
* @param periodicTorsionParameters the force parameters (periodicity, phase, k) for each periodic torsion term
* @param rbTorsionIndices the four atoms connected by each Ryckaert-Bellemans torsion term
* @param rbTorsionParameters the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
* @param bonded14Indices each element contains the indices of two atoms whose nonbonded interactions should be reduced since
* they form a bonded 1-4 pair
* @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
* nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* the standard nonbonded calculation.
* @param nonbondedParameters the nonbonded force parameters (charge, van der Waals radius, van der Waals depth) for each atom
*/
virtual void initialize(const std::vector<std::vector<int> >& bondIndices, const std::vector<std::vector<double> >& bondParameters,
const std::vector<std::vector<int> >& angleIndices, const std::vector<std::vector<double> >& angleParameters,
const std::vector<std::vector<int> >& periodicTorsionIndices, const std::vector<std::vector<double> >& periodicTorsionParameters,
const std::vector<std::vector<int> >& rbTorsionIndices, const std::vector<std::vector<double> >& rbTorsionParameters,
const std::vector<std::vector<int> >& bonded14Indices, const std::vector<std::set<int> >& exclusions,
const std::vector<std::vector<double> >& nonbondedParameters) = 0;
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/
virtual void execute(const Stream& positions, Stream& forces) = 0;
};
/**
* This kernel is invoked by StandardMMForceField to calculate the energy of the system.
*/
class CalcStandardMMEnergyKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcStandardMMEnergy";
}
CalcStandardMMEnergyKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bondIndices the two atoms connected by each bond term
* @param bondParameters the force parameters (length, k) for each bond term
* @param angleIndices the three atoms connected by each angle term
* @param angleParameters the force parameters (angle, k) for each angle term
* @param periodicTorsionIndices the four atoms connected by each periodic torsion term
* @param periodicTorsionParameters the force parameters (periodicity, phase, k) for each periodic torsion term
* @param rbTorsionIndices the four atoms connected by each Ryckaert-Bellemans torsion term
* @param rbTorsionParameters the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
* @param bonded14Indices each element contains the indices of two atoms whose nonbonded interactions should be reduced since
* they form a bonded 1-4 pair
* @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
* nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* the standard nonbonded calculation.
* @param nonbondedParameters the nonbonded force parameters (charge, van der Waals radius, van der Waals depth) for each atom
*/
virtual void initialize(const std::vector<std::vector<int> >& bondIndices, const std::vector<std::vector<double> >& bondParameters,
const std::vector<std::vector<int> >& angleIndices, const std::vector<std::vector<double> >& angleParameters,
const std::vector<std::vector<int> >& periodicTorsionIndices, const std::vector<std::vector<double> >& periodicTorsionParameters,
const std::vector<std::vector<int> >& rbTorsionIndices, const std::vector<std::vector<double> >& rbTorsionParameters,
const std::vector<std::vector<int> >& bonded14Indices, const std::vector<std::set<int> >& exclusions,
const std::vector<std::vector<double> >& nonbondedParameters) = 0;
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @return the potential energy due to the StandardMMForceField
*/
virtual double execute(const Stream& positions) = 0;
};
/**
* This kernel is invoked by GBSAOBCForceField to calculate the forces acting on the system.
*/
class CalcGBSAOBCForcesKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcGBSAOBCForces";
}
CalcGBSAOBCForcesKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bornRadii the initial value of the Born radius for each atom
* @param atomParameters the force parameters (charge, atomic radius, scaling factor) for each atom
* @param solventDielectric the dielectric constant of the solvent
* @param soluteDielectric the dielectric constant of the solute
*/
virtual void initialize(const std::vector<double>& bornRadii, const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric) = 0;
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/
virtual void execute(const Stream& positions, Stream& forces) = 0;
};
/**
* This kernel is invoked by GBSAOBCForceField to calculate the energy of the system.
*/
class CalcGBSAOBCEnergyKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcGBSAOBCEnergy";
}
CalcGBSAOBCEnergyKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bornRadii the initial value of the Born radius for each atom
* @param atomParameters the force parameters (charge, atomic radius, scaling factor) for each atom
* @param solventDielectric the dielectric constant of the solvent
* @param soluteDielectric the dielectric constant of the solute
*/
virtual void initialize(const std::vector<double>& bornRadii, const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric) = 0;
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @return the potential energy due to the GBSAOBCForceField
*/
virtual double execute(const Stream& positions) = 0;
};
/**
* This kernel is invoked by VerletIntegrator to take one time step.
*/
class IntegrateVerletStepKernel : public KernelImpl {
public:
static std::string Name() {
return "IntegrateVerletStep";
}
IntegrateVerletStepKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up all parameters related to integrator.
*
* @param masses the mass of each atom
* @param constraintIndices each element contains the indices of two atoms whose distance should be constrained
* @param constraintLengths the required distance between each pair of constrained atoms
*/
virtual void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices,
const std::vector<double>& constraintLengths) = 0;
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param stepSize the integration step size
*/
virtual void execute(Stream& positions, Stream& velocities, const Stream& forces, double stepSize) = 0;
};
/**
* This kernel is invoked by LangevinIntegrator to take one time step.
*/
class IntegrateLangevinStepKernel : public KernelImpl {
public:
static std::string Name() {
return "IntegrateLangevinStep";
}
IntegrateLangevinStepKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up all parameters related to integrator.
*
* @param masses the mass of each atom
* @param constraintIndices each element contains the indices of two atoms whose distance should be constrained
* @param constraintLengths the required distance between each pair of constrained atoms
*/
virtual void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices,
const std::vector<double>& constraintLengths) = 0;
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param temperature the temperature of the heat bath
* @param friction the friction coefficient coupling the system to the heat bath
* @param stepSize the integration step size
*/
virtual void execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) = 0;
};
/**
* This kernel is invoked by BrownianIntegrator to take one time step.
*/
class IntegrateBrownianStepKernel : public KernelImpl {
public:
static std::string Name() {
return "IntegrateBrownianStep";
}
IntegrateBrownianStepKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up all parameters related to integrator.
*
* @param masses the mass of each atom
* @param constraintIndices each element contains the indices of two atoms whose distance should be constrained
* @param constraintLengths the required distance between each pair of constrained atoms
*/
virtual void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices,
const std::vector<double>& constraintLengths) = 0;
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param temperature the temperature of the heat bath
* @param friction the friction coefficient coupling the system to the heat bath
* @param stepSize the integration step size
*/
virtual void execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) = 0;
};
/**
* This kernel is invoked by AndersenThermostat at the start of each time step to adjust the atom velocities.
*/
class ApplyAndersenThermostatKernel : public KernelImpl {
public:
static std::string Name() {
return "ApplyAndersenThermostat";
}
ApplyAndersenThermostatKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up the values of unchanging parameters.
*
* @param masses the mass of each atom
*/
virtual void initialize(const std::vector<double>& masses) = 0;
/**
* Execute the kernel.
*
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param temperature the temperature of the heat bath
* @param collisionFrequency the frequency at which atom collide with particles in the heat bath
* @param stepSize the integration step size
*/
virtual void execute(Stream& velocities, double temperature, double collisionFrequency, double stepSize) = 0;
};
/**
* This kernel is invoked to calculate the kinetic energy of the system.
*/
class CalcKineticEnergyKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcKineticEnergy";
}
CalcKineticEnergyKernel(std::string name) : KernelImpl(name) {
}
/**
* Initialize the kernel, setting up the atomic masses.
*
* @param masses the mass of each atom
*/
virtual void initialize(const std::vector<double>& masses) = 0;
/**
* Execute the kernel.
*
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @return the kinetic energy of the system
*/
virtual double execute(const Stream& positions) = 0;
};
} // namespace OpenMM
#endif /*OPENMM_KERNELS_H_*/
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "Kernel.h"
using namespace OpenMM;
using namespace std;
Kernel::Kernel() : impl(0) {
}
Kernel::Kernel(KernelImpl* impl) : impl(impl) {
}
Kernel::Kernel(const Kernel& copy) : impl(copy.impl) {
impl->referenceCount++;
}
Kernel::~Kernel() {
impl->referenceCount--;
if (impl->referenceCount == 0)
delete impl;
}
Kernel Kernel::operator=(const Kernel& copy) {
return Kernel(copy);
}
string Kernel::Kernel::getName() const {
return impl->getName();
}
KernelImpl& Kernel::getImpl() {
return *impl;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "KernelImpl.h"
using namespace OpenMM;
using namespace std;
KernelImpl::KernelImpl(string name) : name(name), referenceCount(1) {
}
std::string KernelImpl::getName() const {
return name;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "Platform.h"
#include "PlatformException.h"
#include "Kernel.h"
#include "Stream.h"
#include "KernelFactory.h"
#include "StreamFactory.h"
using namespace OpenMM;
using namespace std;
std::vector<Platform*> Platform::platforms;
void Platform::registerKernelFactory(std::string name, KernelFactory* factory) {
kernelFactories[name] = factory;
}
void Platform::registerStreamFactory(std::string name, StreamFactory* factory) {
streamFactories[name] = factory;
}
bool Platform::supportsKernels(std::vector<std::string> kernelNames) const {
for (int i = 0; i < (int) kernelNames.size(); ++i)
if (kernelFactories.find(kernelNames[i]) == kernelFactories.end())
return false;
return true;
}
Kernel Platform::createKernel(std::string name) const {
if (kernelFactories.find(name) == kernelFactories.end())
throw PlatformException("Called createKernel() on a Platform which does not support the requested kernel");
return Kernel(kernelFactories.find(name)->second->createKernelImpl(name));
}
Stream Platform::createStream(std::string name, int size, Stream::DataType type) const {
return Stream(streamFactories.find(name)->second->createStreamImpl(name, size, type));
}
void Platform::registerPlatform(Platform* platform) {
platforms.push_back(platform);
}
int Platform::getNumPlatforms() {
return platforms.size();
}
Platform& Platform::getPlatform(int index) {
return *platforms[index];
}
Platform& Platform::findPlatform(std::vector<std::string> kernelNames) {
Platform* best = 0;
double speed = 0.0;
for (int i = 0; i < (int) platforms.size(); ++i) {
if (platforms[i]->supportsKernels(kernelNames) && platforms[i]->getSpeed() > speed) {
best = platforms[i];
speed = best->getSpeed();
}
}
if (best == 0)
throw PlatformException("No Platform supports all the requested kernels");
return *best;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "Stream.h"
#include "StreamImpl.h"
using namespace OpenMM;
using namespace std;
Stream::Stream() : impl(0) {
}
Stream::Stream(StreamImpl* impl) : impl(impl) {
}
Stream::Stream(const Stream& copy) : impl(copy.impl) {
impl->referenceCount++;
}
Stream::~Stream() {
impl->referenceCount--;
if (impl->referenceCount == 0)
delete impl;
}
Stream Stream::operator=(const Stream& copy) {
return Stream(copy);
}
string Stream::Stream::getName() const {
return impl->getName();
}
int Stream::getSize() const {
return impl->getSize();
}
Stream::DataType Stream::getDataType() const {
return impl->getDataType();
}
void Stream::loadFromArray(const void* array) {
impl->loadFromArray(array);
}
void Stream::saveToArray(void* array) {
impl->saveToArray(array);
}
void Stream::fillWithValue(void* value) {
impl->fillWithValue(value);
}
StreamImpl& Stream::getImpl() {
return *impl;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "StreamImpl.h"
using namespace OpenMM;
using namespace std;
StreamImpl::StreamImpl(string name, int size, Stream::DataType type) : name(name), size(size), type(type), referenceCount(1) {
}
std::string StreamImpl::getName() const {
return name;
}
int StreamImpl::getSize() const {
return size;
}
Stream::DataType StreamImpl::getDataType() const {
return type;
}
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